Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

  1. #!/bin/sh
  2. export LOCATION=ankara
  3. weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport"
  4. getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;}
  5. # Some very particular and terse stream manipulation. We get the maximum
  6. # precipitation chance and the daily high and low from the downloaded file and
  7. # display them with coresponding emojis.
  8. showweather() { printf "%s" "$(sed '16q;d' "$weatherreport" |
  9. grep -wo "[0-9]*%" | sort -rn | sed "s/^/\^c#81a1c1\^  \^d\^/g;1q" | tr -d '\n')"
  10. sed '13q;d' "$weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " ﰕ " $1 "° 滛 " $2 "°"}' ;}
  11. case $BLOCK_BUTTON in
  12. 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;;
  13. 2) getforecast && showweather ;;
  14. 3) notify-send " Weather module" "\- Left click for full forecast.
  15. - Middle click to update forecast.
  16. : Chance of rain/snow
  17. ﰕ: Daily low
  18. 滛: Daily high" ;;
  19. 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
  20. esac
  21. # The test if our forcecast is updated to the day. If it isn't download a new
  22. # weather report from wttr.in with the above function.
  23. [ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
  24. getforecast
  25. showweather