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.

44 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/sh
  2. source ~/.config.env
  3. weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport"
  4. weatherreportjson="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreportjson"
  5. getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;}
  6. getforecastjson() { curl -sf "wttr.in/$LOCATION?format=j1" > "$weatherreportjson" || exit 1 ;}
  7. # Some very particular and terse stream manipulation. We get the maximum
  8. # precipitation chance and the daily high and low from the downloaded file and
  9. # display them with coresponding emojis.
  10. showweather() {
  11. jq -r ".weather|.[0]|.hourly|.[$(expr $(date '+%H') / 4)]|.FeelsLikeC,.chanceofrain,.chanceofsnow,.WindGustKmph" "$weatherreportjson" |sed ':a;N;$!ba;s/\n/ /g' \
  12. | awk -F' ' '{
  13. if ($4 > 30)
  14. print "^c#ffffff^ ^d^" $4 "kph ^c#ebcb8b^ 盛 ^d^ " $1 "°"
  15. else if ($2 < $3)
  16. print "^c#ffffff^ ^d^" $3 "% ^c#ebcb8b^ 盛 ^d^ " $1 "°"
  17. else
  18. print "^c#81a1c1^ ^d^" $2 "% ^c#ebcb8b^ 盛 ^d^ " $1 "°"}'
  19. }
  20. case $BLOCK_BUTTON in
  21. 1) setsid -f st -c weather -n weather -e less -Srf "$weatherreport" ;;
  22. 2) getforecast && showweather && kill -50 $(pidof dwmblocks) ;;
  23. 3) notify-send " Weather module" "\- Left click for full forecast.
  24. - Middle click to update forecast.
  25. : Chance of rain/snow
  26. ﰕ: Daily low
  27. 滛: Daily high" ;;
  28. 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
  29. esac
  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. [ "$(date -r "/home/yigit/.local/share/weatherreport" "+%d-%m-%Y")" = "$(date '+%d-%m-%Y')" ] ||
  33. getforecast
  34. [ "$(date -r "/home/yigit/.local/share/weatherreportjson" "+%d-%m-%Y %H")" = "$(date '+%d-%m-%Y %H')" ] ||
  35. getforecastjson
  36. showweather