From 09eeeadecdf2fc05da769f7a11f2c6c7c9dc3d19 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Tue, 9 Apr 2024 17:59:42 +0100 Subject: [PATCH] waybar: improve wakatime module data handling --- waybar/resources/custom_modules/wakatime.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/waybar/resources/custom_modules/wakatime.py b/waybar/resources/custom_modules/wakatime.py index deb305b..bde5147 100755 --- a/waybar/resources/custom_modules/wakatime.py +++ b/waybar/resources/custom_modules/wakatime.py @@ -8,8 +8,21 @@ WAKATIME_API_KEY = os.getenv("WAKATIME_API_KEY") WAKATIME_ENDPOINT = "https://wakatime.com/api/v1/users/current/status_bar/today" +class DataPending(Exception): + """Raised when the data is pending or not yet available""" + + pass + + def get_data(url): - response = requests.get(url) + try: + response = requests.get(url, timeout=5) + + except requests.exceptions.Timeout: + raise DataPending("Request timed out. Data may be pending.") + except requests.exceptions.RequestException as e: + raise Exception("Could not fetch data.") + if response.status_code == 200: return response.json() else: @@ -47,6 +60,8 @@ def main(): output["text"] = digital_time output["tooltip"] = tooltip + except DataPending as e: + output["text"] = "Pending" except Exception as e: output["text"] = "Error"