Skip to content

Commit

Permalink
Improve weather template
Browse files Browse the repository at this point in the history
  • Loading branch information
DO1JLR committed Jul 23, 2024
1 parent ab9be3f commit 5fc2c88
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions templates/wttr.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ wttr.in waybar widget
{{ ansible_managed }}
"""
import json
import sys
from datetime import datetime
import requests
import time

localization = {
"en": {
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 5fc2c88

Please sign in to comment.