From 5fc2c88380f0665b34942c2a1320d0512c2dce9d Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 23 Jul 2024 13:27:36 +0200 Subject: [PATCH] Improve weather template --- templates/wttr.py.j2 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/templates/wttr.py.j2 b/templates/wttr.py.j2 index 9965af0..b1f7ea4 100644 --- a/templates/wttr.py.j2 +++ b/templates/wttr.py.j2 @@ -4,8 +4,10 @@ wttr.in waybar widget {{ ansible_managed }} """ import json +import sys from datetime import datetime import requests +import time localization = { "en": { @@ -118,9 +120,16 @@ WEATHER_CODES = { data = {} - -weather = requests.get(f"https://{LANG}.wttr.in/?format=j1", timeout=10).json() - +for i in range(23): + try: + weather_raw = requests.get(f"https://{LANG}.wttr.in/?format=j1", timeout=42) + if weather_raw.status_code == 200: + weather = weather_raw.json() + break + except requests.ConnectionError: + if i == 22: + sys.exit() + time.sleep(1*i*i+1) def format_time(time): """