dotfiles/duskwm/.config/dusk/status_scripts/scripts/get_weather.py

44 lines
1 KiB
Python
Raw Normal View History

2025-06-24 16:57:29 -04:00
import requests
from theme import current_theme, default
# WHO values
# 1-2: Low
# 3-5: Moderate
# 6-7: High
# 8-10: Very High
# 11+: Extreme
uv_index = {
0: current_theme.green,
2: current_theme.yellow,
5: current_theme.orange,
7: current_theme.red,
10: current_theme.magenta,
}
geodata = requests.get("https://ipinfo.io/json").json()
location = geodata["loc"]
city = geodata["city"]
region = geodata["region"]
weather = requests.get(
f"https://wttr.in/{location}?format=+%c+%t+%f+%h+%w+%P+%p+%u"
).text
icon, temp, feels_like, humidity, wind, pressure, precip, uv = weather.split()
bright = f"^v^^c{current_theme.base8}^"
uv_color = [color for index, color in uv_index.items() if int(uv) > index][-1]
uv_color = f"^v^^c{uv_color}^"
humid_color = f"^v^^c{current_theme.blue}^"
precip_color = f"^v^^c{current_theme.teal}^"
# c_templ = t"{i}{t} {w} {h} {p}"
content = (
f"{bright}{icon} "
+ f"{uv_color}{temp}({feels_like})^t^ "
+ f"{wind} "
+ f"{humid_color}{humidity} "
+ f"{precip_color}{precip}^t^"
)