Package acis_xmlrpc :: Module wrcc_http
[hide private]
[frames] | no frames]

Source Code for Module acis_xmlrpc.wrcc_http

 1  import httplib, urllib 
 2  import re 
 3  import datetime 
 4   
5 -def getWRCCDailySummary(stn, start, end, allow_incomplete=False):
6 host = "www.wrcc.dri.edu" 7 prog = "/cgi-bin/wea_dysimts2.pl" 8 9 headers = { 10 "Content-type": "application/x-www-form-urlencoded", 11 "Accept": "text/*" 12 } 13 14 params = urllib.urlencode({ 15 'stn': stn.upper(), 16 'syea': start.strftime("%y"), 17 'smon': start.strftime("%m"), 18 'sday': start.strftime("%d"), 19 'eyea': end.strftime("%y"), 20 'emon': end.strftime("%m"), 21 'eday': end.strftime("%d"), 22 'miss': '01', 23 'unit': 'E', 24 'WsMon': '01', 25 'WsDay': '01', 26 'WeMon': '12', 27 'WeDay': '31', 28 'Ofor': 'A', 29 'obs': 'N', 30 'Datareq': allow_incomplete and 'A' or 'C', 31 'qRS': 'ON', # Solar radiation 32 'qWD': 'ON', # Wind 33 'qAT': 'ON', # Air temp 34 'qRH': 'ON', # Relative humidity 35 'qPR': 'ON', # Precip 36 'qc': 'Y', 37 }) 38 39 conn = httplib.HTTPConnection(host) 40 conn.request("POST", prog, params, headers) 41 response = conn.getresponse() 42 data = response.read() 43 conn.close() 44 return data
45 46 if __name__ == '__main__': 47 """ 48 stn = 'IGRA' 49 start = datetime.date(2007,12,1) 50 end = datetime.date(2008,1,31) 51 print getWRCCDailySummary(stn, start, end) 52 """ 53 stn = 'RA08' 54 start = datetime.date(2007,2,1) 55 end = datetime.date(2007,2,28) 56 print getWRCCDailySummary(stn, start, end, allow_incomplete=True) 57