def five_day(location): ''' Get each weather forecast for the corrosponding coordinates :param coords: the latitude and longitude for which that that weather is being forecasted :type coords: tuple containing the latitude and logitude for the forecast :return casts: the five day, every three hours, forecast for the zip code :type casts: list of Weather objects ''' owm = OWM(masta_key) Forecast = get_data_from_weather_api(owm, location).get_forecast() forecast = json.loads(Forecast.to_JSON()) casts = [ ] # This is for the weather objects created in the for loop below. for data in forecast['weathers']: # Make an _id for the next Weather to be created, create the weather, # append it to the casts list. instant = data['reference_time'] casts.append(Weather(location, 'forecast', data)) return casts # from Extract.make_instants import find_data # # set database and collection for testing # database = 'test' # collection = 'instant_temp' # # create a dict to hold the instants pulled from the database # instants = {} # data = find_data(client, database, collection) # # add each doc to instants and set its key and _id to the same values # for item in data: # instants[f'{item["_id"]}'] = item['_id']
def five_day(coords, code=None): ''' Get each weather forecast for the corrosponding coordinates :param coords: the latitude and longitude for which that that weather is being forecasted :type coords: tuple containing the latitude and logitude for the forecast :return five_day: the five day, every three hours, forecast for the zipcode :type five_day: dict ''' owm = OWM(masta_key) Forecast = get_data_from_weather_api(owm, coords=coords).get_forecast() forecast = json.loads(Forecast.to_JSON()) if code: forecast['zipcode'] = code if coords: forecast['coordinates'] = coords forecast.pop('Location') forecast.pop('interval') reception_time = forecast['reception_time'] # to add to weathers array for cast in forecast['weathers']: cast['zipcode'] = forecast['zipcode'] cast['instant'] = cast.pop('reference_time') cast['time_to_instant'] = cast['instant'] - reception_time return forecast
def five_day(location): ''' Get each weather forecast for the corrosponding coordinates :param coords: the latitude and longitude for which that that weather is being forecasted :type coords: tuple containing the latitude and logitude for the forecast :return casts: the five day, every three hours, forecast for the zip code :type casts: list of Weather objects ''' owm = OWM(masta_key) Forecast = get_data_from_weather_api(owm, location).get_forecast() forecast = json.loads(Forecast.to_JSON()) casts = [ ] # This is for the weather objects created in the for loop below. for data in forecast['weathers']: # Make an _id for the next Weather to be created, create the weather, # append it to the casts list. instant = data['reference_time'] casts.append(Weather(location, 'forecast', data)) return casts