voidrice/.scripts/statusbar/weather

24 lines
1 KiB
Text
Raw Normal View History

2018-09-04 18:16:38 +00:00
#!/bin/sh
2019-04-01 02:22:51 +00:00
location="$1"; [ -z "$location" ] || location="$location+"
getforecast() { ping -q -c 1 1.1.1.1 >/dev/null || exit 1
curl -s "wttr.in/$location" > "$HOME/.local/share/weatherreport" || exit 1 ;}
showweather() { printf "%s" "$(sed '16q;d' "$HOME/.local/share/weatherreport" | grep -wo "[0-9]*%" | sort -n | sed -e '$!d' | sed -e "s/^/☔ /g" | tr -d '\n')"
sed '13q;d' "$HOME/.local/share/weatherreport" | grep -o "m\\(-\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " ❄️",$1 "°","🌞",$2 "°"}' ;}
2018-04-23 00:39:23 +00:00
case $BLOCK_BUTTON in
2019-04-01 02:22:51 +00:00
1) $TERMINAL -e less -S "$HOME/.local/share/weatherreport" ;;
2) getforecast && showweather ;;
2019-04-02 23:20:26 +00:00
3) pgrep -x dunst >/dev/null && notify-send "🌈 Weather module" "\- Left click for full forecast.
2019-04-01 02:22:51 +00:00
- Middle click to update forecast.
☔: Chance of rain/snow
❄: Daily low
🌞: Daily high" ;;
esac
2018-04-23 00:39:23 +00:00
2019-04-01 02:22:51 +00:00
if [ "$(stat -c %y "$HOME/.local/share/weatherreport" | awk '{print $1}')" != "$(date '+%Y-%m-%d')" ]
then getforecast && showweather
else showweather
fi