2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
2022-08-10 17:01:49 +02:00
|
|
|
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
|
|
|
|
weatheremoji="${XDG_CACHE_HOME:-$HOME/.cache}/weatheremoji"
|
2022-07-04 21:36:33 +02:00
|
|
|
url="wttr.in/Karlsruhe"
|
|
|
|
opt="?F"
|
|
|
|
emojiopt="?format=1"
|
|
|
|
convertemoji() {
|
|
|
|
sed -i '
|
|
|
|
s/☀️//
|
|
|
|
s/☁️//
|
|
|
|
s/⛅️//
|
|
|
|
s/⛈//
|
|
|
|
s/✨//
|
|
|
|
s/❄️//
|
|
|
|
s/🌦//
|
|
|
|
s/🌧//
|
|
|
|
s/🌨//
|
|
|
|
s/🌩//
|
|
|
|
s/🌫//
|
2022-08-10 17:01:49 +02:00
|
|
|
' "${weatheremoji}"
|
2022-07-04 21:36:33 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 00:01:38 +02:00
|
|
|
getforecast() { curl -sf "$url$opt" > "$weatherreport" && curl -sf "$url$emojiopt" > "$weatheremoji" ;}
|
2022-08-10 17:01:49 +02:00
|
|
|
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')"
|
2022-08-16 00:01:38 +02:00
|
|
|
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 "°"}' ;}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
|
|
|
[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
|
|
|
|
getforecast && convertemoji
|
2022-08-16 00:01:38 +02:00
|
|
|
|
2022-07-04 21:36:33 +02:00
|
|
|
showweather
|