SimplyAutomationized

pythonET from agrimet

May 4th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import urllib2,csv,json,time
  2.  
  3. class Struct:
  4.     def __init__(self, **entries):
  5.         self.__dict__.update(entries)
  6.        
  7. class GetET:
  8.     def __init__(self,station):
  9.         self.station=station
  10.         self.ET=Struct(**self.getET())
  11.     def getET(self):
  12.         year = str(time.localtime()[0])[2:]
  13.         url = 'http://www.usbr.gov/pn/agrimet/chart/'+self.station+year+'et.txt'
  14.         response = urllib2.urlopen(url)
  15.         html = response.read()
  16.         dateindex=html.index("DATE")
  17.         items=html[dateindex::].split('\n')[0].split(' ')[:-1]
  18.         items = [value for value in items if value != '']
  19.         data = html[dateindex:].split('\n')[2:]
  20.         data = [value for value in data if value != '']
  21.         yestET = data[len(data)-2].split(' ')[1::]
  22.         yestET = [value for value in yestET if value != '']
  23.         eT={}
  24.         for i,info in enumerate(yestET):
  25.             eT[items[i]]=info
  26.    
  27.         return eT
Advertisement
Add Comment
Please, Sign In to add comment