From 319db74bce8f8ef5281cb00e61cf3d2610ddfc10 Mon Sep 17 00:00:00 2001 From: Jacob Babor Date: Mon, 15 Jun 2026 00:00:56 -0500 Subject: [PATCH] More polishing up --- hyprland/.config/waybar/config | 4 +-- .../.config/waybar/scripts/openai-rate.py | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/hyprland/.config/waybar/config b/hyprland/.config/waybar/config index 33edfb68..d62bf3df 100644 --- a/hyprland/.config/waybar/config +++ b/hyprland/.config/waybar/config @@ -160,14 +160,14 @@ "return-type": "json", "exec": "$HOME/.config/waybar/scripts/openai-rate.py --window primary", "exec-if": "test -r ~/.codex/auth.json", - "format": "5h {}" + "format": " {}" }, "custom/codex-secondary": { "interval": 15, "return-type": "json", "exec": "$HOME/.config/waybar/scripts/openai-rate.py --window secondary", "exec-if": "test -r ~/.codex/auth.json", - "format": "W {}" + "format": " {}" }, "custom/backup": { "interval": 60, diff --git a/hyprland/.config/waybar/scripts/openai-rate.py b/hyprland/.config/waybar/scripts/openai-rate.py index 319ada1f..a87f9ae4 100755 --- a/hyprland/.config/waybar/scripts/openai-rate.py +++ b/hyprland/.config/waybar/scripts/openai-rate.py @@ -81,17 +81,18 @@ def window_label(seconds): return "usage" minutes = math.ceil(seconds / 60) - windows = ( - (5 * 60, "5h"), - (24 * 60, "daily"), - (7 * 24 * 60, "weekly"), - (30 * 24 * 60, "monthly"), - (365 * 24 * 60, "annual"), - ) - for expected, label in windows: - if expected * 0.95 <= minutes <= expected * 1.05: - return label - return "usage" + if minutes < 90: + return f"{minutes}m" + + hours = round(minutes / 60) + if hours < 36: + return f"{hours}h" + + days = round(hours / 24) + if days < 365: + return f"{days}d" + + return f"{round(days / 365)}y" def reset_text(seconds): @@ -183,7 +184,7 @@ def selected_window_output(data, source, selector): klass = usage_class(window["used"], rate_limit.get("limit_reached")) tooltip = [window["tooltip"], f"{window['left']}% remaining", f"source: {source}"] - waybar(f"{window['left']}%", klass, "\n".join(tooltip)) + waybar(f"{window['left']}% {window['label']}", klass, "\n".join(tooltip)) def combined_output(data, source):