def get_forecast24(self, bot, clientid, postcode, when): if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug( "Getting 24 hour weather forecast for [%s] at time [%s]" % (postcode, when)) googlemaps = GoogleMaps(bot.license_keys) latlng = googlemaps.get_latlong_for_location(postcode) met_office = MetOffice(bot.license_keys) forecast = met_office.daily_forecast(latlng.latitude, latlng.longitude) if forecast is not None: return forecast.get_latest().to_program_y_text() else: return None
def test_daily_forecast(self): met_office = MetOffice(self.license_keys) self.assertIsNotNone(met_office) forecast = met_office.daily_forecast(self.lat, self.lng) self.assertIsNotNone(forecast) report = forecast.get_latest_report() self.assertIsNotNone(report) date = DateFormatter.year_month_day_now() report = forecast.get_report_for_date(date) self.assertIsNotNone(report) day_datapoint = report.get_time_period_by_type('Day') self.assertIsNotNone(day_datapoint) self.assertIsInstance(day_datapoint, DailyForecastDayDataPoint) night_datapoint = report.get_time_period_by_type('Night') self.assertIsNotNone(night_datapoint) self.assertIsInstance(night_datapoint, DailyForecastNightDataPoint)
def test_daily_forecast(self): met_office = MetOffice(self.license_keys) self.assertIsNotNone(met_office) met_office.set_daily_forecast_response_file( os.path.dirname(__file__) + "/forecast_daily.json") forecast = met_office.daily_forecast(self.lat, self.lng) self.assertIsNotNone(forecast) report = forecast.get_latest_report() self.assertIsNotNone(report) date = DateFormatter.year_month_day(2017, 4, 3) report = forecast.get_report_for_date(date) self.assertIsNotNone(report) day_datapoint = report.get_time_period_by_type('Day') self.assertIsNotNone(day_datapoint) self.assertIsInstance(day_datapoint, DailyForecastDayDataPoint) night_datapoint = report.get_time_period_by_type('Night') self.assertIsNotNone(night_datapoint) self.assertIsInstance(night_datapoint, DailyForecastNightDataPoint)