Пример #1
0
    def execute(self, bot, clientid, data):
        logging.debug("GeoCode [%s]" % (data))

        words = data.split(" ")
        if words[0] == 'POSTCODE1':
            location = words[1]
        elif words[0] == 'POSTCODE2':
            location = words[1] + words[2]
        elif words[0] == 'LOCATION':
            location = " ".join(words[1:])
        else:
            return None

        googlemaps = GoogleMaps()
        latlng = googlemaps.get_latlong_for_location(location)
        if latlng is not None:
            str_lat = str(latlng.latitude)
            str_lng = str(latlng.longitude)

            lats = str_lat.split(".")
            lngs = str_lng.split(".")

            return "LATITUDE DEC %s FRAC %s LONGITUDE DEC %s FRAC %s" % (
                lats[0], lats[1], lngs[0], lngs[1])

        return None
Пример #2
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()
Пример #3
0
    def test_location(self):
        googlemaps = GoogleMaps(None)

        latlng = googlemaps.get_latlong_for_location("KY3 9UR")
        self.assertIsNotNone(latlng)
        self.assertIsInstance(latlng, LatLong)
        self.assertEqual(latlng.latitude, 56.0720397)
        self.assertEqual(latlng.longitude, -3.1752001)
Пример #4
0
    def test_location(self):
        googlemaps = GoogleMaps(None)

        latlng = googlemaps.get_latlong_for_location("KY3 9UR")
        self.assertIsNotNone(latlng)
        self.assertIsInstance(latlng, LatLong)
        self.assertEquals(latlng.latitude, 56.0720397)
        self.assertEquals(latlng.longitude, -3.1752001)
Пример #5
0
    def test_location(self):
        googlemaps = GoogleMaps()

        filename = os.path.dirname(__file__) + "/location.json"
        # If this line fails, you need to generate test data using programy.utils.geo.google_geo.GoogleMaps static methods
        self.assertTrue(os.path.isfile(filename))

        googlemaps.set_response_file_for_get_latlong_for_location(filename)

        latlng = googlemaps.get_latlong_for_location("KY3 9UR")
        self.assertIsNotNone(latlng)
        self.assertIsInstance(latlng, LatLong)
        self.assertEquals(latlng.latitude, 56.0720397)
        self.assertEquals(latlng.longitude, -3.1752001)
Пример #6
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
Пример #7
0
    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