Advertisement
clairec

Untitled

Dec 16th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import requests
  2. import xml.parsers.expat as expat
  3.  
  4. wxVars = {}
  5.  
  6. def weathervarshandler(name, attributes):
  7. if (name != "variable"):
  8. return
  9. wxVars[attributes["var"]] =attributes["value"]
  10.  
  11. def main():
  12. wxUrl = "http://www.wrh.noaa.gov/mesowest/getobextXml.php?sid=KFAT&num=1"
  13. wxReq = requests.get(wxUrl)
  14. wxXml = wxReq.text
  15. wxParse = expat.ParserCreate()
  16. wxParse.StartElementHandler = weathervarshandler
  17. wxParse.Parse(wxXml, 1)
  18. for i in wxVars:
  19. print(i)
  20. print(wxVars[i])
  21.  
  22.  
  23. if (__name__ == "__main__"):
  24. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement