43 lines
1.3 KiB
Bash
Executable File
43 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
|
|
weatheremoji="${XDG_CACHE_HOME:-$HOME/.cache}/weatheremoji"
|
|
url="wttr.in/Karlsruhe"
|
|
opt="?F"
|
|
emojiopt="?format=1"
|
|
convertemoji() {
|
|
sed -i '
|
|
s/☀️//
|
|
s/☁️//
|
|
s/⛅️//
|
|
s/⛈//
|
|
s/✨//
|
|
s/❄️//
|
|
s/🌦//
|
|
s/🌧//
|
|
s/🌨//
|
|
s/🌩//
|
|
s/🌫//
|
|
' "${weatheremoji}"
|
|
}
|
|
|
|
getforecast() { curl -sf "$url$opt" > "$weatherreport" && curl -sf "$url$emojiopt" > "$weatheremoji" ;}
|
|
showweather() { emoji=$(cat "$weatheremoji") && printf "%s" "$(sed '16q;d' "$weatherreport" |
|
|
grep -wo "[0-9]*%" | sort -rn | sed "s/^/ $(printf %.1s "$emoji") /g;1q" | tr -d '\n')"
|
|
sed '13q;d' "$weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " " $1 "°"," " $2 "°"}' ;}
|
|
|
|
case $BLOCK_BUTTON in
|
|
1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;;
|
|
2) getforecast && showweather ;;
|
|
3) notify-send " Weather module" "\- Left click for full forecast.
|
|
- Middle click to update forecast.
|
|
${emoji}: Chance of rain/snow
|
|
: Daily low
|
|
: Daily high" ;;
|
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
|
esac
|
|
|
|
[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
|
|
getforecast && convertemoji
|
|
|
|
showweather
|