1 #!/bin/sh 2 3 # Displays todays precipication chance (☔) and daily low (🥶) and high (🌞). 4 # Usually intended for the statusbar. 5 6 # If we have internet, get a weather report from wttr.in and store it locally. 7 # You could set up a shell alias to view the full file in a pager in the 8 # terminal if desired. This function will only be run once a day when needed. 9 weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" 10 getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;} 11 12 # Some very particular and terse stream manipulation. We get the maximum 13 # precipitation chance and the daily high and low from the downloaded file and 14 # display them with coresponding emojis. 15 showweather() { printf "%s" "$(sed '16q;d' "$weatherreport" | 16 grep -wo "[0-9]*%" | sort -rn | sed "s/^/☔/g;1q" | tr -d '\n')" 17 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 "°"}' ;} 18 19 case $BLOCK_BUTTON in 20 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; 21 2) getforecast && showweather ;; 22 3) notify-send "🌈 Weather module" "\- Left click for full forecast. 23 - Middle click to update forecast. 24 ☔: Chance of rain/snow 25 🥶: Daily low 26 🌞: Daily high" ;; 27 6) "$TERMINAL" -e "$EDITOR" "$0" ;; 28 esac 29 30 # The test if our forcecast is updated to the day. If it isn't download a new 31 # weather report from wttr.in with the above function. 32 [ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || 33 getforecast 34 35 showweather