1
0
Fork 0
dotfiles/.local/bin/statusbar/sb-forecast

20 lines
846 B
Bash
Executable File

#!/bin/sh
# Options can be found at https://wttr.in/:help
weatherfile="$XDG_CACHE_HOME/weatherreport"
emojifile="$XDG_CACHE_HOME/weatheremoji"
url="wttr.in/?FA"
getforecast() {
curl -sf4 "$url" >$weatherfile || exit 1
curl -sf4 "$url&format=%c" | sed 's/☀️//;s/☁️//;s/⛅️//;s/⛈//;s/✨//;s/❄️//;s/🌦//;s/🌧//;s/🌨//;s/🌩//;s/🌫//;' >$emojifile || exit 1
}
showweather() {
emoji="$(printf "\033[12m%s\033[10m" $(cut -d ' ' -f 1 $emojifile))"
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
showweather