#!/bin/sh # Displays today's precipication chance (ā˜”), and daily low (šŸ„¶) and high (šŸŒž). # Usually intended for the statusbar. LOCATION="Moscow" url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; } # Forecast should be updated only once a day. checkforecast() { [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] } getprecipchance() { echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file grep -wo "[0-9]*%" | # Find a sequence of digits followed by '%' sort -rn | # Sort in descending order head -1q # Extract first line } getdailyhighlow() { echo "$weatherdata" | sed '13q;d' | # Extract line 13 from file grep -o "m\\([-+]\\)*[0-9]\\+" | # Find temperatures in the format "m" sed 's/[+m]//g' | # Remove '+' and 'm' sort -g | # Sort in ascending order sed -e 1b -e '$!d' # Extract the first and last lines } readfile() { weatherdata="$(cat "$weatherreport")" ;} showweather() { readfile printf "ā˜”%s šŸ„¶%sĀ° šŸŒž%sĀ°\n" "$(getprecipchance)" $(getdailyhighlow) } openterm() { hyprctl dispatch exec "[float; size 1800 1300;]" '$TERMINAL -e sh -c "curl wttr.in/Moscow; read _"' } case $1 in 1) hyprctl dispatch exec "[float; size 1700 1100;]" "$TERMINAL -e less -Sfr \"$weatherreport\"" ;; 2) getforecast && showweather ;; 3) notify-send "šŸŒˆ Weather module" "\- Left click for full forecast. - Middle click to update forecast. ā˜”: Chance of rain/snow šŸ„¶: Daily low šŸŒž: Daily high" ;; 6) hyprctl dispatch exec "$TERMINAL -e \"$EDITOR\" \"$0\"" ;; esac checkforecast || getforecast showweather