def testtimeseriesfunc(): m = Meso(api_token='3428e1e281164762870915d2ae6781b4') timeseries = m.timeseries_obs(stid='kfnl', start='201504261800', end='201504262300') ok_(timeseries)
temp = str(x['OBSERVATIONS']['air_temp_value_1']['value']) + u'\N{DEGREE SIGN}' + 'F' wind = x['OBSERVATIONS']['wind_speed_value_1']['value'] + ' mph' result = 'The current weather at ' + st_name + ' is ' + temp + ' with a sustained wind of ' + wind print(result) # I import Pretty Print to make the returned dictionary look, well, pretty. pp = pprint.PrettyPrinter(indent=2) # Instance a Meso object by passing in YOUR api_token m = Meso(api_token='3428e1e281164762870915d2ae6781b4') # this token for testing only # Here we retrieve only the stations in Larimer County, Colorado stations = m.station_list(state='CO', county='Larimer') # Calling variable_list() returns all possible sensor variables at stations variables = m.variable_list() # This returns a climatology for Denver from Apr 26 OOz to Apr 27 OOz climate = m.climatology_obs(stid='kden', startclim='04260000', endclim='04270000', units='precip|in') # Fetches the latest obs for Fort Collins airport within 30 min of Apr 26 18z latest = m.latest_obs(stid='kfnl', attime='201504261800', within='30') # Returns a time series from Fort Collins airport from Apr 26 18z to Apr 26 23z time = m.timeseries_obs(stid='kfnl', start='201504261800', end='201504262300') # Returns the precip obs from Fort Collins airport from Apr 26 18z to Apr 27 12z precip = m.precipitation_obs(stid='kfnl', start='201504261800', end='201504271200', units='precip|in') #pp.pprint(stations)
import sys #The script creats one file for each station (stationName.json) stations = ['SCBH1','KKRH1','KTAH1','PLHH1','C0875','KFWH1','MKRH1','SCEH1','SCSH1','WNVH1'] #Mesowest token x = Meso('ecbfdf783690489eb29d50b18b700827') for station in range(len(stations)): orig_stdout = sys.stdout fileName = stations[station] + ".json" f = file(fileName, 'w') sys.stdout = f returned = x.timeseries_obs(stid=stations[station], start='201401010000', end='201501010500', obtimezone='local', vars='solar_radiation') #returned = x.latest_obs(stid='KKRH1, SCBH1, KTAH1, PLHH1', obtimezone='local', vars='solar_radiation', within='1440' ) #write the json file print (json.dumps(returned, indent = 4)) sys.stdout = orig_stdout f.close() #Delete the first line of each file, it is necessary because the first line does not make part of the json file for station in range (len(stations)): fileName = stations[station] + ".json" lines = open(fileName, 'r').readlines() lines[0] = "\n"