1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
#!/bin/sh
# Displays today's snow chance (๐), precipication chance (โ), humidity (๐ง), wind speed (๐), and current (feel like) temperature (๐).
# Usually intended for the statusbar.
LOCATION=$(curl -s http://ip-api.com/json | jq -r '[.regionName, .countryCode] | join(",")')
url="${WTTRURL:-wttr.in}"
weatherreport="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport"
weatherreportjson="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport.json"
error() {
notify-send -u critical "โ Failed to update 'weather$1'"
exit 1
}
# Get a weather report from 'wttr.in' and save it locally.
getweatherreport() {
(timeout --signal=1 10s curl -sf "$url/$LOCATION" >"$weatherreport" &&
printf "\nUpdated: %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" >>"$weatherreport") ||
error "report"
}
getweatherreportjson() {
timeout --signal=1 10s curl -sf "$url/$LOCATION?format=j1" >"$weatherreportjson" ||
error "reportjson"
grep -q 'Unknown' "$weatherreportjson" && error "reportjson"
}
# Forecast should be updated every 3 hours, but set 3600 to check for reliability.
checkforecast() {
[ -s "$1" ] && [ "$(($(date +%s) - $(stat -c %Y "$1")))" -le 3600 ]
}
get_current_hour() { date +%H | sed 's/^0*//'; }
get_nearest_hourly() {
current_hour=$(get_current_hour)
hour_index=$((current_hour / 3))
jq ".weather[0].hourly[$hour_index]" "$weatherreportjson"
}
getprecip() { get_nearest_hourly | jq -r '.chanceofrain'; }
gethighprecip() { jq -r '.weather[0].hourly[].chanceofrain' "$weatherreportjson" | sort -rn | head -1; }
getsnow() { get_nearest_hourly | jq -r '.chanceofsnow'; }
getwind() { get_nearest_hourly | jq -r '.windspeedKmph'; }
gettemp() { get_nearest_hourly | jq -r '.tempC'; }
getfeelslike() { get_nearest_hourly | jq -r '.FeelsLikeC'; }
getlowtemp() { jq -r '.weather[0].hourly[].tempC' "$weatherreportjson" | sort -n | head -1; }
gethightemp() { jq -r '.weather[0].hourly[].tempC' "$weatherreportjson" | sort -rn | head -1; }
gethumidity() {
humidity=$(get_nearest_hourly | jq -r '.humidity')
case "$humidity" in
[0-9] | [1-2][0-9]) echo "๐๏ธ: $humidity%" ;;
[3-4][0-9]) echo "๐ฒ: $humidity%" ;;
[5-6][0-9]) echo "๐ง: $humidity%" ;;
[7-8][0-9]) echo "๐ฆ: $humidity%" ;;
9[0-9] | 100) echo "๐: $humidity%" ;;
esac
}
getdesc() { get_nearest_hourly | jq -r '.weatherDesc[0].value' | sed 's/ $//'; }
showweather() {
case "$(gettemp)" in
-[0-9]* | 0) icon="๐ฅถ" ;; # Temperature <= 0
[1-9] | [1-2][0-9]) icon="๐" ;; # Temperature 1โ29
3* | [4-9]*) icon="๐ฅต" ;; # Temperature >= 30
esac
[ -n "$(gettemp)" ] && echo "$icon$(gettemp)ยฐ"
}
todayweather() {
printf "๐ Today's weather: %s\n๐: %s%%\nโ: %s(%s)mโงธs\n%s\n๐: %sm/s\n๐: %sยฐ(%sยฐ)\n๐ฅถ: %sยฐ\n๐ฅต: %sยฐ\n" \
"$(getdesc)" "$(getsnow)" "$(getprecip)" "$(gethighprecip)" "$(gethumidity)" "$(getwind)" "$(gettemp)" "$(getfeelslike)" "$(getlowtemp)" "$(gethightemp)"
}
# Show a Doppler RADAR of a user's preferred location.
secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds.
radarloc="${XDG_CACHE_HOME:-${HOME}/.cache}/radar"
doppler="${XDG_CACHE_HOME:-${HOME}/.cache}/doppler.gif"
pickloc() {
chosen="$(echo "US: CONUS: Continental United States
US: Northeast
US: Southeast
US: PacNorthWest
US: PacSouthWest
US: UpperMissVly
US: SouthMissVly
US: SouthPlains
US: NorthRockies
US: SouthRockies
US: Alaska
US: Carib
US: Hawaii
US: CentGrLakes
US: Conus-Large
US: KABR: Aberdeen, SD
US: KBIS: Bismarck, ND
US: KFTG: Denver/Boulder, CO
US: KDMX: Des Moines, IA
US: KDTX: Detroit, MI
US: KDDC: Dodge City, KS
US: KDLH: Duluth, MN
US: KCYS: Cheyenne, WY
US: KLOT: Chicago, IL
US: KGLD: Goodland, KS
US: KUEX: Hastings, NE
US: KGJX: Grand Junction, CO
US: KGRR: Grand Rapids, MI
US: KMVX: Fargo/Grand Forks, ND
US: KGRB: Green Bay, WI
US: KIND: Indianapolis, IN
US: KJKL: Jackson, KY
US: KARX: La Crosse, WI
US: KILX: Lincoln/Central Illinois, IL
US: KLVX: Louisville, KY
US: KMQT: Marquette
US: KMKX: Milwaukee, WI
US: KMPX: Minneapolis, MN
US: KAPX: Gaylord/Alpena, MI
US: KLNX: North Platte, NE
US: KIWX: N. Webster/Northern, IN
US: KOAX: Omaha, NE
US: KPAH: Paducah, KY
US: KEAX: Pleasant Hill, MO
US: KPUX: Pueblo, CO
US: KDVN: Quad Cities, IA
US: KUDX: Rapid City, SD
US: KRIW: Riverton, WY
US: KSGF: Springfield, MO
US: KLSX: St. LOUIS, MO
US: KFSD: Sioux Falls, SD
US: KTWX: Topeka, KS
US: KICT: Wichita, KS
US: KVWX: Paducah, KY
US: ICAO: Responsible Wfo
US: KLTX: WILMINGTON, NC
US: KCCX: State College/Central, PA
US: KLWX: Sterling, VA
US: KFCX: Blacksburg/Roanoke, VA
US: KRAX: Raleigh/Durham, NC
US: KGYX: Portland, ME
US: KDIX: Mt Holly/Philadelphia, PA
US: KPBZ: Pittsburgh, PA
US: KAKQ: Wakefield, VA
US: KMHX: Morehead City, NC
US: KGSP: Greer/Greenville/Sprtbg, SC
US: KILN: Wilmington/Cincinnati, OH
US: KCLE: Cleveland, OH
US: KCAE: Columbia, SC
US: KBGM: Binghamton, NY
US: KENX: Albany, NY
US: KBUF: Buffalo, NY
US: KCXX: Burlington, VT
US: KCBW: Caribou, ME
US: KBOX: Boston /Taunton, MA
US: KOKX: New York City, NY
US: KCLX: Charleston, SC
US: KRLX: Charleston, WV
US: ICAO: Responsible WFO
US: KBRO: Brownsville, TX
US: KABX: Albuquerque, NM
US: KAMA: Amarillo, TX
US: KFFC: Peachtree City/Atlanta, GA
US: KEWX: Austin/Sanantonio, TX
US: KBMX: Birmingham, AL
US: KCRP: Corpus Christi, TX
US: KFWS: Dallas / Ft. Worth, TX
US: KEPZ: El Paso, TX
US: KHGX: Houston/ Galveston, TX
US: KJAX: Jacksonville, FL
US: KBYX: Key West, FL
US: KMRX: Morristown/knoxville, TN
US: KLBB: Lubbock, TX
US: KLZK: Little Rock, AR
US: KLCH: Lake Charles, LA
US: KOHX: Nashville, TN
US: KMLB: Melbourne, FL
US: KNQA: Memphis, TN
US: KAMX: Miami, FL
US: KMAF: Midland/odessa, TX
US: KTLX: Norman, OK
US: KHTX: Huntsville, AL
US: KMOB: Mobile, AL
US: KTLH: Tallahassee, FL
US: KTBW: Tampa Bay Area, FL
US: KSJT: San Angelo, TX
US: KINX: Tulsa, OK
US: KSRX: Tulsa, OK
US: KLIX: New Orleans/slidell, LA
US: KDGX: Jackson, MS
US: KSHV: Shreveport, LA
US: ICAO: Responsible WFO
US: KLGX: Seattle / Tacoma, WA
US: KOTX: Spokane, WA
US: KEMX: Tucson, AZ
US: KYUX: Phoenix, AZ
US: KNKX: San Diego, CA
US: KMUX: Monterey/san Francisco, CA
US: KHNX: San Joaquin/hanford, CA
US: KSOX: San Diego, CA
US: KATX: Seattle / Tacoma, WA
US: KIWA: Phoenix, AZ
US: KRTX: Portland, OR
US: KSFX: Pocatello, ID
US: KRGX: Reno, NV
US: KDAX: Sacramento, CA
US: KMTX: Salt Lake City, UT
US: KPDT: Pendleton, OR
US: KMSX: Missoula, MT
US: KESX: Las Vegas, NV
US: KVTX: Los Angeles, CA
US: KMAX: Medford, OR
US: KFSX: Flagstaff, AZ
US: KGGW: Glasgow, MT
US: KLRX: Elko, NV
US: KBHX: Eureka, CA
US: KTFX: Great Falls, MT
US: KCBX: Boise, ID
US: KBLX: Billings, MT
US: KICX: Salt Lake City, UT
US: ICAO: Responsible Wfo W/ MSCF
US: PABC: Anchorage, AK
US: PAPD: Fairbanks, AK
US: PHKM: Honolulu, HI
US: PAHG: Anchorage, AK
US: PAKC: Anchorage, AK
US: PAIH: Anchorage, AK
US: PHMO: Honolulu, HI
US: PAEC: Fairbanks, AK
US: TJUA: San Juan, PR
US: PACG: Juneau, AK
US: PHKI: Honolulu, HI
US: PHWA: Honolulu, HI
US: ICAO: Responsible Wfo W/ MSCF
US: KFDR: Norman, OK
US: PGUA: Guam
US: KBBX: Sacramento, CA
US: KFDX: Albuquerque, NM
US: KGWX: Jackson, MS
US: KDOX: Wakefield, VA
US: KDYX: San Angelo, TX
US: KEYX: Las Vegas, NV
US: KEVX: Mobile, AL
US: KHPX: Paducah, KY
US: KTYX: Burlington, VT
US: KGRK: Dallas / Ft. Worth, TX
US: KPOE: Lake Charles, LA
US: KEOX: Tallahassee, FL
US: KHDX: El Paso, TX
US: KDFX: San Antonio, TX
US: KMXX: Birmingham, AL
US: KMBX: Bismarck, ND
US: KVAX: Jacksonville, FL
US: KJGX: Peachtree City/atlanta, GA
US: KVNX: Norman, OK
US: KVBX: Vandenberg Afb: Orcutt, CA
EU: Europe
EU: GB: Great Brittain
EU: SCAN: Scandinavia. Norway, Sweden And Denmark
EU: ALPS: The Alps
EU: NL: The Netherlands
EU: DE: Germany
EU: SP: Spain
EU: FR: France
EU: IT: Italy
EU: PL: Poland
EU: GR: Greece
EU: TU: Turkey
EU: RU: Russia
EU: BA: Bahrain
EU: BC: Botswana
EU: SE: Republic of Seychelles
EU: HU: Hungary
EU: UK: Ukraine
AF: AF: Africa
AF: WA: West Africa
AF: ZA: South Africa
AF: DZ: Algeria
AF: CE: Canary Islands
AF: NG: Nigeria
AF: TD: Chad
AF: CG: Democratic Republic of Congo
AF: EG: Egypt
AF: ET: Ethiopia
AF: CM: Cameroon
AF: IS: Israel
AF: LY: Libya
AF: MG: Madagascar
AF: MO: Morocco
AF: BW: Namibia
AF: SA: Saudi Arabia
AF: SO: Somalia
AF: SD: Sudan
AF: TZ: Tanzania
AF: TN: Tunisia
AF: ZM: Zambia
AF: KE: Kenya
AF: AO: Angola
DE: BAW: Baden-Wรผrttemberg
DE: BAY: Bavaria
DE: BBB: Berlin
DE: BBB: Brandenburg
DE: HES: Hesse
DE: MVP: Mecklenburg-Western Pomerania
DE: NIB: Lower Saxony
DE: NIB: Bremen
DE: NRW: North Rhine-Westphalia
DE: RPS: Rhineland-Palatinate
DE: RPS: Saarland
DE: SAC: Saxony
DE: SAA: Saxony-Anhalt
DE: SHH: Schleswig-Holstein
DE: SHH: Hamburg
DE: THU: Thuringia" | dmenu -r -i -l 50 -p "Select a radar to use as default:" | tr "[:lower:]" "[:upper:]")"
# Ensure user did not escape.
[ -z "$chosen" ] && exit 1
# Set continent code and radar code.
continentcode=${chosen%%:*}
radarcode=${chosen#* } radarcode=${radarcode%:*}
# Print codes to $radarloc file.
printf "%s,%s\\n" "$continentcode" "$radarcode" >"$radarloc"
}
getdoppler() {
cont=$(cut -c -2 "$radarloc")
loc=$(cut -c 4- "$radarloc")
notify-send "๐ฆ๏ธ Doppler RADAR" "Pulling most recent Doppler RADAR for $loc."
case "$cont" in
"US") curl -sL "https://radar.weather.gov/ridge/standard/${loc}_loop.gif" >"$doppler" ;;
"EU") curl -sL "https://api.sat24.com/animated/${loc}/rainTMC/2/" >"$doppler" ;;
"AF") curl -sL "https://api.sat24.com/animated/${loc}/rain/2/" >"$doppler" ;;
"DE")
loc="$(echo "$loc" | tr "[:upper:]" "[:lower:]")"
curl -sL "https://www.dwd.de/DWD/wetter/radar/radfilm_${loc}_akt.gif" >"$doppler"
;;
esac
}
showdoppler() { setsid -f mpv --no-osc --loop=inf --no-terminal "$doppler"; }
case $BLOCK_BUTTON in
1)
[ "$MANPAGER" = "less -s" ] && pager=true || pager=false
[ "$pager" = "false" ] && {
export MANPAGER='less -s'
export LESS="R"
export LESS_TERMCAP_mb="$(printf '%b' '[1;31m')"
export LESS_TERMCAP_md="$(printf '%b' '[1;36m')"
export LESS_TERMCAP_me="$(printf '%b' '[0m')"
export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')"
export LESS_TERMCAP_se="$(printf '%b' '[0m')"
export LESS_TERMCAP_us="$(printf '%b' '[1;32m')"
export LESS_TERMCAP_ue="$(printf '%b' '[0m')"
export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null"
}
setsid -f "$TERMINAL" -e less -Sf "${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport"
[ "$pager" = "false" ] && {
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT="-c"
}
;;
2)
[ ! -f "$radarloc" ] && pickloc && getdoppler
[ $(($(date '+%s') - $(stat -c %Y "$doppler"))) -gt "$secs" ] && getdoppler
showdoppler
;;
3)
notify-send "๐ Weather module (updates every 3 hours)" "\- Left click for full forecast
- Shift + left click to update forecast
๐: Chance of snow (hidden if it's 0)
โ: Chance of rain
๐ง: Humidity (icon changes depending on the level)
๐: Wind speed
๐: Current (feel like) temperature
๐ฅถ: Daily lowest temperature
๐ฅต: Daily highest temperature"
notify-send "$(todayweather)"
notify-send "๐บ๏ธ Doppler RADAR module" "\- Middle click for local Doppler RADAR
- Shift + middle click to update RADAR location
After $secs seconds, new clicks will also automatically update the doppler RADAR"
;;
6) getweatherreport && getweatherreportjson && notify-send "๐ Updated forecast" ;;
7) pickloc && getdoppler && showdoppler ;;
8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
checkforecast "$weatherreport" || { getweatherreport && pkill -RTMIN+15 "${STATUSBAR:-dwmblocks}" && sleep 3; }
checkforecast "$weatherreportjson" || { getweatherreportjson && pkill -RTMIN+15 "${STATUSBAR:-dwmblocks}" && sleep 3; }
showweather
|