Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. ### API Information ###
  5. # This script uses the Dark Sky weather API. You will need to register an account to get an API key. The first 1000 API requests you make every day are free of charge.
  6. # Documentation overview: https://darksky.net/dev/docs
  7. # Account overview: https://darksky.net/dev/account
  8.  
  9. # Define your location. api.darksky.net/forecast/api_key/latitude,longitude?... If you want Fahrenheit, use units=us
  10. address="https://api.darksky.net/forecast/you_api_key/naprimer55.7507,37.6177?units=si&exclude=minutely,hourly,daily,alerts,flags"
  11. weather="$(wget -q -O- $address)"
  12.  
  13. # Look for the current weather conditions
  14. [[ "$weather" =~ \"icon\":\"([^\"]*)\" ]]
  15. condition="${BASH_REMATCH[1]}"
  16.  
  17. # Look for the current apparent temperature. Use \"temperature\", if you like.
  18. [[ "$weather" =~ \"apparentTemperature\":([^,]*), ]]
  19. temperature="${BASH_REMATCH[1]}"
  20.  
  21. # Print some spacing, and a cloud icon. If you can't see the icon, install otf-fontawesome from the AUR or find it for your distribution
  22. printf "\040"
  23.  
  24. # Print a rounded temperature value
  25. LC_ALL=C /usr/bin/printf '%.0f' " $temperature"
  26.  
  27. # Use either Celsius or Fahrenheit character
  28. if grep -qi 'units=us' <<< $address; then
  29. printf "°F"
  30. else
  31. printf "°C"
  32. fi
  33.  
  34. # Print edgy shit about the weather
  35. if grep -qi 'rain' <<< $condition; then
  36. printf " Pluviophile dreams"
  37. elif grep -qi 'partly-cloudy' <<< $condition; then
  38. printf " It's alright"
  39. elif grep -qi 'cloudy' <<< $condition; then
  40. printf " Grey and dull"
  41. elif grep -qi 'clear-day' <<< $condition; then
  42. printf " Diffuse sky radiation"
  43. elif grep -qi 'clear-night' <<< $condition; then
  44. printf " Look up at the stars."
  45. elif grep -qi 'snow' <<< $condition; then
  46. printf " It's snowing!"
  47. elif grep -qi 'fog' <<< $condition; then
  48. printf " Spooky."
  49. elif grep -qi 'wind' <<< $condition; then
  50. printf " Don't fly away"
  51. elif grep -qi 'sleet' <<< $condition; then
  52. printf " Sleet. Stay inside"
  53. # Next 3 may not be defined yet.
  54. elif grep -qi 'thunderstorm' <<< $condition; then
  55. printf " The gods are wrathful"
  56. elif grep -qi 'hail' <<< $condition; then
  57. printf " Hail. Stay inside"
  58. elif grep -qi 'tornado' <<< $condition; then
  59. printf " Tornado. Stay inside. Or don't. You'll probably never see this text. Basement? Be careful."
  60. else
  61. printf " Look out the window"
  62. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement