blob: ebbdf58587b09782f8f484fbac7277dd623b5cdc (
plain)
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
|
#!/bin/sh
# Displays today's precipication chance (ā), and daily low (š„¶) and high (š).
# Usually intended for the statusbar.
LOCATION="Moscow"
url="${WTTRURL:-wttr.in}"
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
# Get a weather report from 'wttr.in' and save it locally.
getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
getprecipchance() {
echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file
grep -wo "[0-9]*%" | # Find a sequence of digits followed by '%'
sort -rn | # Sort in descending order
head -1q # Extract first line
}
getdailyhighlow() {
echo "$weatherdata" | sed '13q;d' | # Extract line 13 from file
grep -o "m\\([-+]\\)*[0-9]\\+" | # Find temperatures in the format "m<signed number>"
sed 's/[+m]//g' | # Remove '+' and 'm'
sort -g | # Sort in ascending order
sed -e 1b -e '$!d' # Extract the first and last lines
}
readfile() { weatherdata="$(cat "$weatherreport")" ;}
showweather() {
readfile
printf "ā%s š„¶%sĀ° š%sĀ°\n" "$(getprecipchance)" $(getdailyhighlow)
}
openterm() {
hyprctl dispatch exec "[float; size 1800 1300;]" 'kitty -e sh -c "curl wttr.in/Moscow; read _"'
}
case $1 in
1) hyprctl dispatch exec "[float; size 1800 1300;]" 'kitty -e sh -c "curl wttr.in/Moscow; read _"'
;;
3) notify-send "š Weather module" "\- Left click for full forecast.
- Middle click to update forecast.
ā: Chance of rain/snow
š„¶: Daily low
š: Daily high" ;;
6) kitty -e "$EDITOR" "$0" ;;
esac
getforecast
showweather
|