import requests from theme import current_theme, default # WHO values # 0: No Sunlight so treat as low # 1-2: Low # 3-5: Moderate # 6-7: High # 8-10: Very High # 11+: Extreme uv_index = { -1: current_theme.green, # -1 allows for UV Index of 0 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^" )