32 lines
983 B
Bash
Executable File
32 lines
983 B
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 "°"}' ;}
|
|
|
|
[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
|
|
getforecast && convertemoji
|
|
|
|
showweather
|