Skip to content

Commit 6e10654

Browse files
authored
Port waybar weather module pr from hyprdots (#19)
Port of prasanthrangan/hyprdots#1818 ## Type of change - [ ] **Bug fix** (non-breaking change which fixes an issue) - [x] **New feature** (non-breaking change which adds functionality) - [ ] **Breaking change** (fix or feature that would cause existing functionality to not work as expected) - [ ] **Documentation update** (non-breaking change; modified files are limited to the documentations) - [ ] **Technical debt** (a code change that does not fix a bug or add a feature but makes something clearer for devs) - [ ] **Other** (provide details below)
2 parents f3c4c8a + 52b3c06 commit 6e10654

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

Diff for: Configs/.config/waybar/config.ctl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
0|28|bottom|( cpu memory custom/cpuinfo custom/gpuinfo ) ( idle_inhibitor clock ) ( hyprland/workspaces )|( hyprland/window )|( backlight network pulseaudio pulseaudio#microphone custom/updates custom/keybindhint ) ( privacy tray battery ) ( custom/wallchange custom/theme custom/wbar custom/cliphist custom/power )
44
0|28|top|( cpu memory custom/cpuinfo ) ( idle_inhibitor clock ) ( hyprland/workspaces )|( hyprland/window )|( backlight network pulseaudio pulseaudio#microphone custom/updates custom/keybindhint ) ( privacy tray battery ) ( custom/wallchange custom/theme custom/wbar custom/cliphist custom/power )
55
0||bottom|( hyprland/workspaces hyprland/window )|( idle_inhibitor clock )|( cpu memory custom/cpuinfo custom/gpuinfo ) ( backlight network pulseaudio pulseaudio#microphone custom/updates custom/keybindhint ) ( privacy tray battery ) ( custom/wallchange custom/theme custom/wbar custom/cliphist custom/power )
6-
0||top|( hyprland/workspaces hyprland/window )|( idle_inhibitor clock )|( cpu memory custom/cpuinfo custom/gpuinfo ) ( backlight network pulseaudio pulseaudio#microphone custom/updates custom/keybindhint ) ( privacy tray battery ) ( custom/wallchange custom/theme custom/wbar custom/cliphist custom/power )
6+
0||top|( hyprland/workspaces hyprland/window )|( idle_inhibitor clock )|( cpu memory custom/cpuinfo custom/gpuinfo ) ( backlight network pulseaudio pulseaudio#microphone custom/updates custom/keybindhint custom/weather ) ( privacy tray battery ) ( custom/wallchange custom/theme custom/wbar custom/cliphist custom/power )
77
1|31|bottom|( custom/power custom/cliphist custom/wbar custom/theme custom/wallchange ) ( wlr/taskbar custom/spotify ) |( idle_inhibitor clock )|( privacy tray battery ) ( backlight network pulseaudio pulseaudio#microphone custom/notifications custom/keybindhint )
88
0|31|left|( custom/power custom/cliphist custom/wbar custom/theme custom/wallchange ) ( wlr/taskbar custom/spotify ) |( idle_inhibitor clock )|( privacy tray battery ) ( backlight network pulseaudio pulseaudio#microphone custom/keybindhint )
99
0|31|top|( custom/power custom/cliphist custom/wbar custom/theme custom/wallchange ) ( wlr/taskbar custom/spotify ) |( idle_inhibitor clock )|( privacy tray battery ) ( backlight network pulseaudio pulseaudio#microphone custom/keybindhint )

Diff for: Configs/.config/waybar/modules/weather.jsonc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"custom/weather": {
2+
"exec": "${ScrDir}/weather.py ",
3+
"tooltip" : true,
4+
"format" : "{}",
5+
"interval" : 30,
6+
"return-type" : "json"
7+
},

Diff for: Configs/.local/lib/hyde/weather.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
import requests
5+
from datetime import datetime
6+
7+
WEATHER_CODES = {
8+
'113': '☀️ ',
9+
'116': '⛅ ',
10+
'119': '☁️ ',
11+
'122': '☁️ ',
12+
'143': '☁️ ',
13+
'176': '🌧️',
14+
'179': '🌧️',
15+
'182': '🌧️',
16+
'185': '🌧️',
17+
'200': '⛈️ ',
18+
'227': '🌨️',
19+
'230': '🌨️',
20+
'248': '☁️ ',
21+
'260': '☁️ ',
22+
'263': '🌧️',
23+
'266': '🌧️',
24+
'281': '🌧️',
25+
'284': '🌧️',
26+
'293': '🌧️',
27+
'296': '🌧️',
28+
'299': '🌧️',
29+
'302': '🌧️',
30+
'305': '🌧️',
31+
'308': '🌧️',
32+
'311': '🌧️',
33+
'314': '🌧️',
34+
'317': '🌧️',
35+
'320': '🌨️',
36+
'323': '🌨️',
37+
'326': '🌨️',
38+
'329': '❄️ ',
39+
'332': '❄️ ',
40+
'335': '❄️ ',
41+
'338': '❄️ ',
42+
'350': '🌧️',
43+
'353': '🌧️',
44+
'356': '🌧️',
45+
'359': '🌧️',
46+
'362': '🌧️',
47+
'365': '🌧️',
48+
'368': '🌧️',
49+
'371': '❄️',
50+
'374': '🌨️',
51+
'377': '🌨️',
52+
'386': '🌨️',
53+
'389': '🌨️',
54+
'392': '🌧️',
55+
'395': '❄️ '
56+
}
57+
58+
data = {}
59+
60+
61+
weather = requests.get("https://wttr.in/?format=j1").json()
62+
63+
64+
def format_time(time):
65+
return time.replace("00", "").zfill(2)
66+
67+
68+
def format_temp(temp):
69+
return (hour['FeelsLikeC']+"°").ljust(3)
70+
71+
def format_chances(hour):
72+
chances = {
73+
"chanceoffog": "Fog",
74+
"chanceoffrost": "Frost",
75+
"chanceofovercast": "Overcast",
76+
"chanceofrain": "Rain",
77+
"chanceofsnow": "Snow",
78+
"chanceofsunshine": "Sunshine",
79+
"chanceofthunder": "Thunder",
80+
"chanceofwindy": "Wind"
81+
}
82+
83+
conditions = []
84+
for event in chances.keys():
85+
if int(hour[event]) > 0:
86+
conditions.append(chances[event]+" "+hour[event]+"%")
87+
return ", ".join(conditions)
88+
89+
tempint = int(weather['current_condition'][0]['FeelsLikeC'])
90+
extrachar = ''
91+
if tempint > 0 and tempint < 10:
92+
extrachar = '+'
93+
94+
95+
data['text'] = ' '+WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \
96+
" "+extrachar+weather['current_condition'][0]['FeelsLikeC']+"°" +" | "+ weather['nearest_area'][0]['areaName'][0]['value']+\
97+
", " + weather['nearest_area'][0]['country'][0]['value']
98+
99+
data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°</b>\n"
100+
data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°\n"
101+
data['tooltip'] += f"Location: {weather['nearest_area'][0]['areaName'][0]['value']}\n"
102+
data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
103+
data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n"
104+
for i, day in enumerate(weather['weather']):
105+
data['tooltip'] += f"\n<b>"
106+
if i == 0:
107+
data['tooltip'] += "Today, "
108+
if i == 1:
109+
data['tooltip'] += "Tomorrow, "
110+
data['tooltip'] += f"{day['date']}</b>\n"
111+
data['tooltip'] += f"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° "
112+
data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n"
113+
for hour in day['hourly']:
114+
if i == 0:
115+
if int(format_time(hour['time'])) < datetime.now().hour-2:
116+
continue
117+
data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"
118+
119+
120+
print(json.dumps(data))

Diff for: Scripts/custom_hypr.lst

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ qt5-imageformats # for dolphin image thumb
4848
ffmpegthumbs # for dolphin video thumbnails
4949
kde-cli-tools # for dolphin file type defaults
5050
libnotify # for notifications
51+
wttrbar # for weather
52+
python-requests # scrpit dependency
5153

5254
# --------------------------------------------------- // Theming
5355
nwg-look # gtk configuration tool

0 commit comments

Comments
 (0)