Example #1
0
    def execute(self, bot, clientid, data):

        splits = data.split()
        if len(splits) < 4:
            return None

        if splits[0] == 'LOCATION':
            postcode = splits[1]
        else:
            return None

        if splits[2] == 'WHEN':
            when = splits[3]
        else:
            return None

        if logging.getLogger().isEnabledFor(logging.DEBUG):
            logging.debug("Getting weather for %s at time %s", postcode, when)

        googlemaps = GoogleMaps(bot.license_keys)
        latlng = googlemaps.get_latlong_for_location(postcode)

        if logging.getLogger().isEnabledFor(logging.DEBUG):
            logging.debug(
                "Weather - Calling external weather service for with extra data [%s]",
                data)

        met_office = MetOffice(bot.license_keys)

        observation = met_office.current_observation(latlng.latitude,
                                                     latlng.longitude)

        return observation.get_latest().to_program_y_text()
Example #2
0
    def get_observation(self, bot, clientid, postcode, when):
        if logging.getLogger().isEnabledFor(logging.DEBUG):
            logging.debug("Getting weather observation 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)

        observation = met_office.current_observation(latlng.latitude,
                                                     latlng.longitude)
        if observation is not None:
            return observation.get_latest().to_program_y_text()
        else:
            return None
Example #3
0
    def test_observation(self):
        met_office = MetOffice(self.license_keys)
        self.assertIsNotNone(met_office)

        observation = met_office.current_observation(self.lat, self.lng)
        self.assertIsNotNone(observation)

        report = observation.get_latest_report()
        self.assertIsNotNone(report)

        date = DateFormatter.year_month_day_now()
        report = observation.get_report_for_date(date)
        self.assertIsNotNone(report)

        datapoint = report.get_time_period_by_time("300")
        self.assertIsNotNone(datapoint)
        self.assertIsInstance(datapoint, ObservationDataPoint)
Example #4
0
    def test_observation(self):
        met_office = MetOffice(self.license_keys)
        self.assertIsNotNone(met_office)

        met_office.set_current_observation_response_file(
            os.path.dirname(__file__) + "/observation.json")

        observation = met_office.current_observation(self.lat, self.lng)
        self.assertIsNotNone(observation)

        report = observation.get_latest_report()
        self.assertIsNotNone(report)

        date = DateFormatter.year_month_day(2017, 4, 3)
        report = observation.get_report_for_date(date)
        self.assertIsNotNone(report)

        datapoint = report.get_time_period_by_time("300")
        self.assertIsNotNone(datapoint)
        self.assertIsInstance(datapoint, ObservationDataPoint)