openweathermap-fullfeatured.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. get_duration() {
  41. osname=$(uname -s)
  42. case $osname in
  43. *BSD) date -r "$1" -u +%H:%M;;
  44. *) date --date="@$1" -u +%H:%M;;
  45. esac
  46. }
  47. KEY="e434b5435a979de6e155570590bee89b"
  48. CITY="Novosibirsk"
  49. UNITS="metric"
  50. SYMBOL="°"
  51. API="https://api.openweathermap.org/data/2.5"
  52. if [ -n "$CITY" ]; then
  53. if [ "$CITY" -eq "$CITY" ] 2>/dev/null; then
  54. CITY_PARAM="id=$CITY"
  55. else
  56. CITY_PARAM="q=$CITY"
  57. fi
  58. current=$(curl -sf "$API/weather?appid=$KEY&$CITY_PARAM&units=$UNITS")
  59. forecast=$(curl -sf "$API/forecast?appid=$KEY&$CITY_PARAM&units=$UNITS&cnt=1")
  60. else
  61. location=$(curl -sf https://location.services.mozilla.com/v1/geolocate?key=geoclue)
  62. current=$(curl -sf "$API/weather?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS")
  63. fi
  64. if [ -n "$current" ] && [ -n "$forecast" ]; then
  65. current_temp=$(echo "$current" | jq ".main.temp" | cut -d "." -f 1)
  66. current_icon=$(echo "$current" | jq -r ".weather[0].icon")
  67. echo " $current_temp$SYMBOL"
  68. fi