From 4431e54740fc169acfc3d6d95dfff167d74e04fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Wed, 20 Nov 2024 21:09:57 +0100 Subject: [PATCH] Update arrhist script --- home/hyprland/waybar/arrhist.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/home/hyprland/waybar/arrhist.py b/home/hyprland/waybar/arrhist.py index 38006cc..33c3156 100644 --- a/home/hyprland/waybar/arrhist.py +++ b/home/hyprland/waybar/arrhist.py @@ -6,6 +6,7 @@ from datetime import datetime, date, timedelta SECRET_DIR = "/home/torjus/.config/sops-nix/secrets" + def sonarr_url(): xdg_dir = os.environ["XDG_RUNTIME_DIR"] if not xdg_dir: @@ -13,26 +14,31 @@ def sonarr_url(): with open(f"{SECRET_DIR}/sonarr_base_url") as f: return f.read().strip() + def radarr_url(): with open(f"{SECRET_DIR}/radarr_base_url") as f: return f.read().strip() + def make_header(api_key: str): return {"X-Api-Key": api_key, "Accept": "application/json"} + def get_sonarr_key(): with open(f"{SECRET_DIR}/sonarr_api_key") as f: return f.read().strip() + def get_radarr_key(): with open(f"{SECRET_DIR}/radarr_api_key") as f: return f.read().strip() -def get_sonarr_history(since: datetime|None=None): + +def get_sonarr_history(since: datetime | None = None): api_key = get_sonarr_key() if not since: - since = datetime.combine(date.today()-timedelta(days=1),datetime.min.time()) - url = f"{sonarr_url()}/api/history/since" + since = datetime.combine(date.today() - timedelta(days=1), datetime.min.time()) + url = f"{sonarr_url()}/api/v3/history/since" url += f"?date={since.isoformat()}" response = requests.get(url, headers=make_header(api_key)) response.raise_for_status() @@ -44,10 +50,11 @@ def get_sonarr_history(since: datetime|None=None): items.append(item["sourceTitle"]) return items -def get_radarr_history(since: datetime|None=None): + +def get_radarr_history(since: datetime | None = None): api_key = get_radarr_key() if not since: - since = datetime.combine(date.today()-timedelta(days=7),datetime.min.time()) + since = datetime.combine(date.today() - timedelta(days=7), datetime.min.time()) url = f"{radarr_url()}/api/v3/history/since" url += f"?date={since.isoformat()}" response = requests.get(url, headers=make_header(api_key)) @@ -60,12 +67,17 @@ def get_radarr_history(since: datetime|None=None): items.append(item["sourceTitle"]) return items + if __name__ == "__main__": sonarr_items = get_sonarr_history() radarr_items = get_radarr_history() output = { "text": f"Son: {len(sonarr_items)}|Rad: {len(radarr_items)}", - "tooltip": "Radarr: \n" + "\n".join(radarr_items) + "\n" + "Sonarr: \n" + "\n".join(sonarr_items) + "tooltip": "Radarr: \n" + + "\n".join(radarr_items) + + "\n" + + "Sonarr: \n" + + "\n".join(sonarr_items), } print(json.dumps(output))