def retrieve_forecasts(coords, resolution): cached_forecasts = [] missing_forecasts = [] for coord in coords: cached_forecast = cache_repo.find(coord, (resolution)*.95) if cached_forecast: cached_forecast.coordinates = coord cached_forecasts.append(cached_forecast) else: missing_forecasts.append(coord) logging.info('missing coords: %s', len(missing_forecasts)) logging.info('cached coords: %s', len(cached_forecasts)) if missing_forecasts: new_forecast_dwml = noaa_proxy.request_dwml_grid_points(missing_forecasts) logging.debug('dwml new forecasts: %s', new_forecast_dwml) parser = DWML_Parser(new_forecast_dwml) new_forecasts = parser.generate_forecast_grid() logging.debug('new forecasts: %s', new_forecasts) for new_forecast in new_forecasts: cache_repo.insert(new_forecast) else: new_forecasts = [] return new_forecasts + cached_forecasts
def test_find_with_no_match(self): coord = Coordinates(23.12, 124.2) resolution = 34 result = cache_repo.find(coord, resolution) assert_equal(result, None)