weather.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. get_icon() {
  3. case $1 in
  4. # Icons for weather-icons
  5. 01d) icon="";;
  6. 01n) icon="";;
  7. 02d) icon="";;
  8. 02n) icon="";;
  9. 03*) icon="";;
  10. 04*) icon="";;
  11. 09d) icon="";;
  12. 09n) icon="";;
  13. 10d) icon="";;
  14. 10n) icon="";;
  15. 11d) icon="";;
  16. 11n) icon="";;
  17. 13d) icon="";;
  18. 13n) icon="";;
  19. 50d) icon="";;
  20. 50n) icon="";;
  21. *) icon="";
  22. # Icons for Font Awesome 5 Pro
  23. #01d) icon="";;
  24. #01n) icon="";;
  25. #02d) icon="";;
  26. #02n) icon="";;
  27. #03d) icon="";;
  28. #03n) icon="";;
  29. #04*) icon="";;
  30. #09*) icon="";;
  31. #10d) icon="";;
  32. #10n) icon="";;
  33. #11*) icon="";;
  34. #13*) icon="";;
  35. #50*) icon="";;
  36. #*) icon="";
  37. esac
  38. echo $icon
  39. }
  40. # KEY="e434b5435a979de6e155570590bee89b" # CITY="Novosibirsk"
  41. KEY="7834197c2338888258f8cb94ae14ef49" # from Qtile
  42. CITY="Homel"
  43. UNITS="metric"
  44. SYMBOL="°"
  45. API="https://api.openweathermap.org/data/2.5"
  46. if [ -n "$CITY" ]; then
  47. if [ "$CITY" -eq "$CITY" ] 2>/dev/null; then
  48. CITY_PARAM="id=$CITY"
  49. else
  50. CITY_PARAM="q=$CITY"
  51. fi
  52. weather=$(curl -sf "$API/weather?appid=$KEY&$CITY_PARAM&units=$UNITS")
  53. else
  54. location=$(curl -sf https://location.services.mozilla.com/v1/geolocate?key=geoclue)
  55. if [ -n "$location" ]; then
  56. location_lat="$(echo "$location" | jq '.location.lat')"
  57. location_lon="$(echo "$location" | jq '.location.lng')"
  58. weather=$(curl -sf "$API/weather?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS")
  59. fi
  60. fi
  61. if [ -n "$weather" ]; then
  62. weather_temp=$(echo "$weather" | jq ".main.temp" | cut -d "." -f 1)
  63. weather_icon=$(echo "$weather" | jq -r ".weather[0].icon")
  64. echo "$weather_temp$SYMBOL"
  65. fi