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.

96 lines
3.1 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
4 years ago
4 years ago
4 years ago
  1. #!/bin/bash
  2. source ~/.config/config.env
  3. weatherreport="${XDG_CACHE_HOME:-$HOME/.local/share}/weatherreport"
  4. weatherreportjson="${XDG_CACHE_HOME:-$HOME/.local/share}/weatherreportjson"
  5. WCODES=(
  6. ["113"]="^c#ebcb8b^ "
  7. ["116"]="^c#ebcb8b^杖"
  8. ["119"]="^c#ffffff^摒"
  9. ["122"]="^c#ffffff^ "
  10. ["143"]="^c#ffffff^ "
  11. ["176"]="^c#81a1c1^ "
  12. ["179"]="^c#81a1c1^ "
  13. ["182"]="^c#81a1c1^ "
  14. ["185"]="^c#81a1c1^ "
  15. ["200"]="^c#81a1c1^ "
  16. ["227"]="^c#ffffff^ "
  17. ["230"]="^c#ffffff^ "
  18. ["248"]="^c#ffffff^ "
  19. ["260"]="^c#ffffff^ "
  20. ["263"]="^c#81a1c1^ "
  21. ["266"]="^c#81a1c1^ "
  22. ["281"]="^c#81a1c1^ "
  23. ["284"]="^c#81a1c1^ "
  24. ["293"]="^c#81a1c1^ "
  25. ["296"]="^c#81a1c1^ "
  26. ["299"]="^c#81a1c1^ "
  27. ["302"]="^c#81a1c1^ "
  28. ["305"]="^c#81a1c1^ "
  29. ["308"]="^c#81a1c1^ "
  30. ["311"]="^c#81a1c1^ "
  31. ["314"]="^c#81a1c1^ "
  32. ["317"]="^c#81a1c1^ "
  33. ["320"]="^c#ffffff^ "
  34. ["323"]="^c#81a1c1^ "
  35. ["326"]="^c#81a1c1^ "
  36. ["329"]="^c#ffffff^ "
  37. ["332"]="^c#ffffff^ "
  38. ["335"]="^c#81a1c1^ "
  39. ["338"]="^c#ffffff^ "
  40. ["350"]="^c#81a1c1^ "
  41. ["353"]="^c#81a1c1^ "
  42. ["356"]="^c#81a1c1^ "
  43. ["359"]="^c#81a1c1^ "
  44. ["362"]="^c#81a1c1^ "
  45. ["365"]="^c#81a1c1^ "
  46. ["368"]="^c#81a1c1^ "
  47. ["371"]="^c#81a1c1^ "
  48. ["374"]="^c#81a1c1^ "
  49. ["377"]="^c#81a1c1^ "
  50. ["386"]="^c#81a1c1^ "
  51. ["389"]="^c#81a1c1^ "
  52. ["392"]="^c#81a1c1^ "
  53. ["395"]="^c#81a1c1^ "
  54. )
  55. getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;}
  56. getforecastjson() { curl -sf "wttr.in/$LOCATION?format=j1" > "$weatherreportjson" || exit 1 ;}
  57. # Some very particular and terse stream manipulation. We get the maximum
  58. # precipitation chance and the daily high and low from the downloaded file and
  59. # display them with coresponding emojis.
  60. showweather() {
  61. data=$(jq -r ".weather|.[0]|.hourly|.[$(expr $(date '+%H') / 4)]|.FeelsLikeC,.chanceofrain,.chanceofsnow,.WindGustKmph,.weatherCode" "$weatherreportjson")
  62. data=$(echo -ne $(echo $data | cut -d' ' -f 1-4)" ${WCODES[$(echo $data | cut -d' ' -f 5)]}")
  63. echo $data | awk -F' ' '{
  64. if ($4 > 30)
  65. print "^c#ffffff^ ^d^" $4 "kh "$5 " ^d^ " $1 "°C"
  66. else if ($2 < $3)
  67. print "^c#ffffff^ ^d^" $3 "% "$5 " ^d^ " $1 "°C"
  68. else
  69. print "^c#81a1c1^ ^d^" $2 "% " $5 " ^d^ " $1 "°C"}'
  70. }
  71. case $BLOCK_BUTTON in
  72. 1) setsid -f st -c weather -n weather -e less -Srf "$weatherreport" ;;
  73. 2) getforecast && showweather && kill -50 $(pidof dwmblocks) ;;
  74. 3) notify-send " Weather module" "\- Left click for full forecast.
  75. - Middle click to update forecast.
  76. : Chance of rain/snow
  77. ﰕ: Daily low
  78. 滛: Daily high" ;;
  79. 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
  80. esac
  81. # The test if our forcecast is updated to the day. If it isn't download a new
  82. # weather report from wttr.in with the above function.
  83. [ "$(date -r "$XDG_CACHE_HOME/weatherreport" "+%d-%m-%Y")" = "$(date '+%d-%m-%Y')" ] ||
  84. getforecast
  85. [ "$(date -r "$XDG_CACHE_HOME/weatherreportjson" "+%d-%m-%Y %H")" = "$(date '+%d-%m-%Y %H')" ] ||
  86. getforecastjson
  87. showweather