wether1.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. API_KEY="you_api"
  3. CITY="Moscow"
  4. UNITS="metric"
  5. URL="https://api.openweathermap.org/data/2.5/weather?q=${CITY}&units=${UNITS}&appid=${API_KEY}"
  6. RESPONSE=$(curl -s "${URL}")
  7. TEMPERATURE=$(echo "${RESPONSE}" | jq -r '.main.temp' | awk '{printf("%.0f",$1)}')
  8. CONDITION=$(echo "${RESPONSE}" | jq -r '.weather[0].main')
  9. DESCRIPTION=$(echo "${RESPONSE}" | jq -r '.weather[0].description')
  10. case ${DESCRIPTION} in
  11. "mist"|"Mist"|"Smoke"|"smoke"|"haze")
  12. ICON="🌫"
  13. ;;
  14. "clear sky"|"Clear")
  15. ICON="☀️"
  16. ;;
  17. "few clouds"|"scattered clouds"|"broken clouds"|"Clouds"|"overcast clouds")
  18. ICON="🌤"
  19. ;;
  20. "shower rain"|"rain"|"light rain"|"moderate rain"|"heavy intensity rain"|"very heavy rain"|"extreme rain"|"light intensity shower rain")
  21. ICON="🌧"
  22. ;;
  23. "thunderstorm"|"Thunderstorm")
  24. ICON="⛈"
  25. ;;
  26. "snow"|"light snow"|"Heavy snow")
  27. ICON="❄️"
  28. ;;
  29. *)
  30. ICON="❓"
  31. ;;
  32. esac
  33. echo "${TEMPERATURE}°C ${ICON}" > /tmp/wether.tmp