Advertisement
DavidsonDFGL

Weather Catcher

May 13th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.25 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Cities I tested:
  4. #Contagem: 3465624
  5. #Belo Hor: 3470127
  6. #Tokyo   : 1850147
  7. #Paris   : 2988507
  8. #Betim   : 3470044
  9.  
  10. cityId=1850147
  11. url=http://openweathermap.org/city/$cityId
  12.  
  13. source=$(curl -s $url)
  14.  
  15. echo "---------------------"
  16. echo "Weather Catcher :D"
  17. echo "---------------------"
  18. city=$(echo "$source" | grep -Pzo "<div class=\"weather-widget\">\n+<h3>.+</h3>" | tail -n1 | cut -d'>' -f2 | cut -d'<' -f1)
  19. echo "City: "$city
  20.  
  21. temp=$(echo "$source" | grep -Pzo "<div class=\"weather-widget\">\n+<h3>.+</h3>\n+<h2>.+<img.+>" | tail -n1 | cut -d'>' -f3 | cut -d'<' -f1)
  22. echo "Temperature: "$temp
  23.  
  24. windComplete=$(echo "$source" | grep -Pzo "<td>Wind</td><td>.+<br>\n.+\n</td>")
  25. wind1=$(echo $windComplete | grep -Eo "</td><td>.+<br>" | cut -d'>' -f3 | cut -d'<' -f1)
  26. wind2=$(echo $windComplete | grep -Eo "<br>.+" | cut -d'>' -f2 | cut -d'<' -f1)
  27. echo "Wind: "
  28. echo "  Desc: "$wind1
  29. echo "  Dir : "$wind2
  30.  
  31. cloud=$(echo "$source" | grep -E "Cloudiness" | cut -d'>' -f5 | cut -d'<' -f1)
  32. echo "Cloudiness: "$cloud
  33.  
  34. pressure=$(echo "$source" | grep -E "Pressure<br>" | cut -d'>' -f6 | cut -d'<' -f1)
  35. echo "Pressure: "$pressure
  36.  
  37. humidity=$(echo "$source" | grep -E "Humidity" | cut -d'>' -f5 | cut -d'<' -f1)
  38. echo "Humidity: "$humidity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement