def run_stationInfo(stn): from get_downloadtime import get_downloadtime station_dict = {} try: from stn_info import stn_info stn = stn.lower() sdict = {} if stn_info.has_key(stn): sdict['id'] = stn for item in ['lat','lon','elev','name','network','vars']: if stn_info[stn].has_key(item): sdict[item] = stn_info[stn][item] dt = get_downloadtime(stn,sdict['network']) if dt == -999: sdict['lasthour'] = "Unknown" else: if dt.hour < 12: hr_str = str(dt.hour)+" AM" elif dt.hour == 12: hr_str = "12 PM" else: hr_str = str(dt.hour-12)+" PM" sdict['lasthour'] = "%d/%d/%d %s" % (dt.month,dt.day,dt.year,hr_str) station_dict['metadata'] = sdict except: print 'Error processing request for',stn print_exception() station_dict['metadata'] = {} json_return = json.dumps(station_dict) return json_return
def run_stationModels(stn): station_dict = {} model_list = [] try: from stn_info import stn_info from pest_models import pest_models stn = stn.lower() if stn_info.has_key(stn): stn_vars = copy.deepcopy(stn_info[stn]['vars']) if 'lwet' in stn_info[stn]['vars'] or 'rhum' in stn_info[stn]['vars']: stn_vars.append('eslw') for mdl in pest_models: mtitle,murl,mvars = mdl for model_var in mvars: if not model_var in stn_vars: break else: whole_url = "http://newa.nrcc.cornell.edu/"+murl+"/"+stn if murl == "newaDisease/onion_dis" or murl == "newaDisease/onion_onlog" or murl == "newaDisease/onion_smbalog" or murl == "newaDisease/onion_sbalog": whole_url = whole_url+"/9999" elif murl == "newaDisease/tomato_for": whole_url = whole_url+"/9999/5" elif murl == "newaDisease/potato_pdays" or murl == "newaDisease/potato_lb": whole_url = whole_url+"/9999/5/1" model_list.append([mtitle,whole_url]) except: print 'Error processing request for',stn print_exception() # station_dict['models'] = model_list sorted_model_list = row_major_list(model_list,3) station_dict['models'] = sorted_model_list json_return = json.dumps(station_dict) return json_return
def getForecastUrl(stn): forecastUrl = "" try: from stn_info import stn_info if not stn_info.has_key(stn): from stn_info_ma import stn_info lat = stn_info[stn]['lat'] lon = stn_info[stn]['lon'] forecastUrl = 'http://forecast.weather.gov/MapClick.php?textField1=%s&textField2=%s' % (lat,lon) return forecastUrl except: return newaCommon_io.errmsg('Error processing request') return forecastUrl