1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_i3wm.git synced 2024-08-16 10:09:53 +02:00

Improve weather template

This commit is contained in:
L3D 2024-07-23 13:27:36 +02:00
parent ab9be3f63a
commit 5fc2c88380
Signed by: l3d
GPG key ID: CD08445BFF4313D1

View file

@ -4,8 +4,10 @@ wttr.in waybar widget
{{ ansible_managed }} {{ ansible_managed }}
""" """
import json import json
import sys
from datetime import datetime from datetime import datetime
import requests import requests
import time
localization = { localization = {
"en": { "en": {
@ -118,9 +120,16 @@ WEATHER_CODES = {
data = {} data = {}
for i in range(23):
weather = requests.get(f"https://{LANG}.wttr.in/?format=j1", timeout=10).json() 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): def format_time(time):
""" """