Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import pymetar
  4. import sys
  5.  
  6.  
  7.  
  8. def get_weather(station_name="EHAM"):
  9. station = station_name
  10.  
  11. try:
  12. rf=pymetar.ReportFetcher(station)
  13. rep=rf.FetchReport()
  14. except Exception, e:
  15. sys.stderr.write("Something went wrong when fetching the report.\n")
  16. sys.stderr.write("These usually are transient problems if the station ")
  17. sys.stderr.write("ID is valid. \nThe error encountered was:\n")
  18. sys.stderr.write(str(e)+"\n")
  19. sys.exit(1)
  20.  
  21. rp=pymetar.ReportParser()
  22. pr=rp.ParseReport(rep)
  23.  
  24. print "Weather report for %s (%s) as of %s" %\
  25. (pr.getStationName(), station, pr.getISOTime())
  26. print "Values of \"None\" indicate that the value is missing from the report."
  27. print "Temperature: %s C / %s F" %\
  28. (pr.getTemperatureCelsius(), pr.getTemperatureFahrenheit())
  29. if pr.getWindchill() and pr.getWindchillF():
  30. print "Wind chill: %.2f C / %.2f F" % (pr.getWindchill(), pr.getWindchillF())
  31.  
  32. print "Rel. Humidity: %s%%" % (pr.getHumidity())
  33. if pr.getWindSpeed() is not None:
  34. print "Wind speed: %0.2f m/s (%i Bft, %0.2f knots)" % \
  35. (pr.getWindSpeed(), pr.getWindSpeedBeaufort(), pr.getWindSpeedKnots())
  36. else:
  37. print "Wind speed: None"
  38.  
  39. print "Wind direction: %s deg (%s)" %\
  40. (pr.getWindDirection(), pr.getWindCompass())
  41. if pr.getPressure() is not None:
  42. print "Pressure: %s hPa" % (int(pr.getPressure()))
  43. else:
  44. print "Pressure: None"
  45.  
  46. print "Dew Point: %s C / %s F" %\
  47. (pr.getDewPointCelsius(), pr.getDewPointFahrenheit())
  48. print "Weather:",pr.getWeather()
  49. print "Sky Conditions:",pr.getSkyConditions()
  50.  
  51.  
  52.  
  53. if __name__ == "__main__":
  54. get_weather()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement