Move folder
This commit is contained in:
124
home/config/waybar/scripts/waybar-wttr.py
Normal file
124
home/config/waybar/scripts/waybar-wttr.py
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/run/current-system/sw/bin/python
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
WEATHER_CODES = {
|
||||
"113": "Sunny",
|
||||
"116": "Patchy",
|
||||
"119": "Cloudy",
|
||||
"122": "Cloudy",
|
||||
"143": "Cloudy",
|
||||
"176": "Rain",
|
||||
"179": "Rain",
|
||||
"182": "Rain",
|
||||
"185": "Rain",
|
||||
"200": "Storm",
|
||||
"227": "Rain",
|
||||
"230": "Rain",
|
||||
"248": "Cloudy",
|
||||
"260": "Cloudy",
|
||||
"263": "Rain",
|
||||
"266": "Rain",
|
||||
"281": "Rain",
|
||||
"284": "Rain",
|
||||
"293": "Rain",
|
||||
"296": "Rain",
|
||||
"299": "Rain",
|
||||
"302": "Rain",
|
||||
"305": "Rain",
|
||||
"308": "Rain",
|
||||
"311": "Rain",
|
||||
"314": "Rain",
|
||||
"317": "Rain",
|
||||
"320": "Rain",
|
||||
"323": "Rain",
|
||||
"326": "Rain",
|
||||
"329": "Snow",
|
||||
"332": "Snow",
|
||||
"335": "Snow",
|
||||
"338": "Snow",
|
||||
"350": "Rain",
|
||||
"353": "Rain",
|
||||
"356": "Rain",
|
||||
"359": "Rain",
|
||||
"362": "Rain",
|
||||
"365": "Rain",
|
||||
"368": "Rain",
|
||||
"371": "Snow",
|
||||
"374": "Rain",
|
||||
"377": "Rain",
|
||||
"386": "Rain",
|
||||
"389": "Rain",
|
||||
"392": "Rain",
|
||||
"395": "Snow",
|
||||
}
|
||||
|
||||
data = {}
|
||||
|
||||
weather = request.get("https://wttr.in/?format=j1").json()
|
||||
|
||||
def format_time(time):
|
||||
return time.replace("00", "").zfill(2)
|
||||
|
||||
def format_temp(temp):
|
||||
return(temp["FeelsLikeC"] + "o").ljust(3)
|
||||
|
||||
def format_chances(hour):
|
||||
chances = {
|
||||
"chancesoffog": "Fog",
|
||||
"chancesoffrost": "Frost",
|
||||
"chancesofovercast": "Overcast",
|
||||
"chancesofrain": "Rain",
|
||||
"chancesofsnow": "Snow",
|
||||
"chancesofsunshine": "Sunshine",
|
||||
"chancesofthunder": "Thunder",
|
||||
"chancesofwindy": "Wind",
|
||||
}
|
||||
|
||||
conditions = []
|
||||
for event in chances.keys():
|
||||
if int(hour[event]) > 0:
|
||||
conditions.append(chances[event] + "" + hour[event] + "%")
|
||||
return ", ".join(conditions)
|
||||
|
||||
tempint = int(weather["current_condition"][0]["FeelsLikeC"])
|
||||
extrachar = ""
|
||||
if tempint > 0 and tempint < 10:
|
||||
extrachar = "+"
|
||||
|
||||
data["text"] = (
|
||||
" "
|
||||
+ WEATHER_CODES[weather["current_condition"][0]["weatherCode"]]
|
||||
+ " "
|
||||
+ extrachar
|
||||
+ weather["current_condition"][0]["FeelsLikeC"]
|
||||
+ "o"
|
||||
)
|
||||
|
||||
data["tooltip"] = (
|
||||
f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}o</b>\n"
|
||||
)
|
||||
data["tooltip"] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}o\n"
|
||||
data["tooltip"] += f"Wind: {weather['current_condition'][0]['WindspeedKmph']}Km/h\n"
|
||||
data["tooltip"] += f"Humidity: {weather['current_condition'][0]['FeelsLikeC']}%\n"
|
||||
for i, day in enumerate(weather["weather"]):
|
||||
data["tooltip"] += f"\n<b>"
|
||||
if i == 0:
|
||||
data["tooltip"] += "Today, "
|
||||
if i == 1:
|
||||
data["tooltip"] += "Tomorrow, "
|
||||
data["tooltip"] += f"{day['date']}</b>\n"
|
||||
data["tooltip"] += f"Up {day['maxtempC']}o Down {day['mintempC']}o "
|
||||
data["tooltip"] += f"Sunrise {day['astronomy'][0]['sunrise']} Sunset {day['astronomy'][0]['sunset']} \n"
|
||||
|
||||
for hour in day["hourly"]:
|
||||
if i == 0"
|
||||
if int(format_time(hour["time"])) < datetime.now().hour - 2:
|
||||
continue
|
||||
|
||||
data["tooltip"] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"
|
||||
|
||||
print(json.dumps(data))
|
||||
Reference in New Issue
Block a user