Skip to content

Commit

Permalink
Fixed the waether to show in C when switching to M
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDoesTech committed May 15, 2023
1 parent 49cac0b commit 7d5a14f
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 35 deletions.
9 changes: 9 additions & 0 deletions HyprV/waybar/conf/mesu-imp.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"tooltip-format": "{: %A, %B %e %Y}"
},

"custom/weather": {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
"return-type" : "json"
},

"temperature": {
"thermal-zone": 1,
"format": "",
Expand Down
9 changes: 9 additions & 0 deletions HyprV/waybar/conf/mesu-met.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"tooltip-format": "{: %A, %e %B %Y}"
},

"custom/weather": {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr-c.py",
"return-type" : "json"
},

"temperature": {
"thermal-zone": 1,
"format": "",
Expand Down
9 changes: 0 additions & 9 deletions HyprV/waybar/conf/v1-config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@
}
},

"custom/weather" : {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
"return-type" : "json"
},

"tray": {
"icon-size": 18,
"spacing": 10
Expand Down
9 changes: 0 additions & 9 deletions HyprV/waybar/conf/v2-config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@
}
},

"custom/weather": {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
"return-type" : "json"
},

"tray": {
"icon-size": 18,
"spacing": 10
Expand Down
9 changes: 0 additions & 9 deletions HyprV/waybar/conf/v3-config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@
"spacing": 10
},

"custom/weather": {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
"return-type" : "json"
},

"custom/updates": {
"format": "{}",
"exec": "~/.config/HyprV/waybar/scripts/update-sys",
Expand Down
11 changes: 3 additions & 8 deletions HyprV/waybar/conf/v4-config-bottom.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
"modules-center": ["wlr/taskbar"],
"modules-right": ["custom/weather"],

"custom/weather": {
//shows the current weather and forecast
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
"return-type" : "json"
},
"include": [
"~/.config/HyprV/waybar/conf/mesu.jsonc"
],

"custom/launch_firefox": {
"format": "",
Expand Down
119 changes: 119 additions & 0 deletions HyprV/waybar/scripts/waybar-wttr-c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python

import json
import requests
from datetime import datetime

WEATHER_CODES = {
'113': '☀️ ',
'116': '⛅ ',
'119': '☁️ ',
'122': '☁️ ',
'143': '☁️ ',
'176': '🌧️',
'179': '🌧️',
'182': '🌧️',
'185': '🌧️',
'200': '⛈️ ',
'227': '🌨️',
'230': '🌨️',
'248': '☁️ ',
'260': '☁️ ',
'263': '🌧️',
'266': '🌧️',
'281': '🌧️',
'284': '🌧️',
'293': '🌧️',
'296': '🌧️',
'299': '🌧️',
'302': '🌧️',
'305': '🌧️',
'308': '🌧️',
'311': '🌧️',
'314': '🌧️',
'317': '🌧️',
'320': '🌨️',
'323': '🌨️',
'326': '🌨️',
'329': '❄️ ',
'332': '❄️ ',
'335': '❄️ ',
'338': '❄️ ',
'350': '🌧️',
'353': '🌧️',
'356': '🌧️',
'359': '🌧️',
'362': '🌧️',
'365': '🌧️',
'368': '🌧️',
'371': '❄️',
'374': '🌨️',
'377': '🌨️',
'386': '🌨️',
'389': '🌨️',
'392': '🌧️',
'395': '❄️ '
}

data = {}


weather = requests.get("https://wttr.in/?format=j1").json()


def format_time(time):
return time.replace("00", "").zfill(2)


def format_temp(temp):
return (hour['FeelsLikeC']+"°").ljust(3)


def format_chances(hour):
chances = {
"chanceoffog": "Fog",
"chanceoffrost": "Frost",
"chanceofovercast": "Overcast",
"chanceofrain": "Rain",
"chanceofsnow": "Snow",
"chanceofsunshine": "Sunshine",
"chanceofthunder": "Thunder",
"chanceofwindy": "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']+"°"

data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°</b>\n"
data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°\n"
data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\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"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° "
data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {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))

0 comments on commit 7d5a14f

Please sign in to comment.