1
0
Fork 0

improve sb-forecast

This commit is contained in:
Luca Bilke 2023-04-03 12:49:26 +02:00
parent 5637c2d691
commit d658f06f39
No known key found for this signature in database
GPG Key ID: 7B77C51E8C779E75
1 changed files with 25 additions and 9 deletions

View File

@ -1,19 +1,35 @@
#!/bin/sh #!/bin/sh
# NOTE: This script takes its dwmblocks update signal as an argument so that it can refresh itself (defaults to 5)
# Options can be found at https://wttr.in/:help # Options can be found at https://wttr.in/:help
weatherfile="$XDG_CACHE_HOME/weatherreport" weatherfile="$XDG_CACHE_HOME/weatherreport"
emojifile="$XDG_CACHE_HOME/weatheremoji" emojifile="$XDG_CACHE_HOME/weatheremoji"
url="wttr.in/?FA" url="wttr.in/$LOCATION"
weatheropts="?FA"
emojiopts="?FA&format=%c"
getforecast() { getforecast() {
curl -sf4 "$url" >$weatherfile || exit 1 curl -sf "$url$weatheropts" >"$weatherfile" || exit 1
curl -sf4 "$url&format=%c" | sed 's/☀️//;s/☁️//;s/⛅️//;s/⛈//;s/✨//;s/❄️//;s/🌦//;s/🌧//;s/🌨//;s/🌩//;s/🌫//;' >$emojifile || exit 1 curl -sf "$url$emojiopts" | sed 's/☀️//;s/☁️//;s/⛅️//;s/⛈//;s/✨//;s/❄️//;s/🌦//;s/🌧//;s/🌨//;s/🌩//;s/🌫//;' | cut -d ' ' -f 1 >"$emojifile" || exit 1
} }
showweather() { fresh() {
emoji="$(printf "\033[12m%s\033[10m" $(cut -d ' ' -f 1 $emojifile))" [ -s "$weatherfile" ] && [ "$(stat -c %y "$weatherfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
sed '16q;d' $weatherfile | grep -wo "[0-9]*%" | sort -rn | sed "s/^/$emoji /g;1q" | tr -d '\n'
sed '13q;d' $weatherfile | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " \033[34;11m\033[0m " $1 "°","\033[31;11m\033[0m " $2 "°"}'
} }
getforecast readfile() {
showweather weather="$(cat "$weatherfile")"
precipitation="$(echo "$weather" | sed '16q;d' | grep -wo "[0-9]*%" | sort -rn | head -1q)"
highlow="$(echo "$weather" | sed '13q;d' | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/[+m]//g' | sort -g | sed -e 1b -e '$!d')"
emoji="$(cat "$emojifile")"
}
output() {
readfile
printf "\033[12m%s\033[10m %s \033[34;11m\033[0m %s° \033[31;11m\033[0m %s°\n" "$emoji" "$precipitation" $highlow
}
if fresh; then
output
else
getforecast && pkill -RTMIN+${1:-5} dwmblocks &
printf " Getting Weather\n"
fi