Hide the secondary codex window if it's not supplied
This commit is contained in:
@@ -146,9 +146,14 @@ def format_window(name, window):
|
||||
}
|
||||
|
||||
|
||||
def get_window(data, selector):
|
||||
rate_limit = data.get("rate_limit") or {}
|
||||
return format_window(selector, rate_limit.get(f"{selector}_window"))
|
||||
|
||||
|
||||
def output_window(data, source, selector):
|
||||
rate_limit = data.get("rate_limit") or {}
|
||||
window = format_window(selector, rate_limit.get(f"{selector}_window"))
|
||||
window = get_window(data, selector)
|
||||
if not window:
|
||||
waybar("n/a", "warning", f"No {selector} usage window returned\nsource: {source}")
|
||||
|
||||
@@ -165,6 +170,11 @@ def parse_args():
|
||||
required=True,
|
||||
help="usage window to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--check",
|
||||
action="store_true",
|
||||
help="exit successfully only when the selected usage window exists",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -172,6 +182,8 @@ def main():
|
||||
args = parse_args()
|
||||
token, account_id, source = load_auth()
|
||||
data = fetch_usage(token, account_id)
|
||||
if args.check:
|
||||
sys.exit(0 if get_window(data, args.window) else 1)
|
||||
output_window(data, source, args.window)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user