def test_distance_uk_driving_imperial(self): googlemaps = GoogleMaps(None) distance = googlemaps.get_distance_between_addresses("Edinburgh", "London", country="UK", mode="driving", units="imperial") self.assertIsNotNone(distance) self.assertIsInstance(distance, GoogleDistance) self.assertEquals("409 mi", distance._distance_text)
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
def test_distance_uk_driving_imperial(self): googlemaps = GoogleMaps(None) distance = googlemaps.get_distance_between_addresses("Edinburgh", "London", country="UK", mode="driving", units="imperial") self.assertIsNotNone(distance) self.assertIsInstance(distance, GoogleDistance) self.assertEqual("409 mi", distance._distance_text)
def test_directions(self): googlemaps = GoogleMaps(None) directions = googlemaps.get_directions_between_addresses( "Edinburgh", "London") self.assertIsNotNone(directions) self.assertIsInstance(directions, GoogleDirections)
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()
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)
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)
def test_directions(self): googlemaps = GoogleMaps(None) filename = os.path.dirname(__file__) + "/directions.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_directions_between_addresses(filename) directions = googlemaps.get_directions_between_addresses("Edinburgh", "London") self.assertIsNotNone(directions) self.assertIsInstance(directions, GoogleDirections)
def test_distance_uk_driving_imperial(self): googlemaps = GoogleMaps(None) filename = os.path.dirname(__file__) + "/distance.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_distance_between_addresses(filename) distance = googlemaps.get_distance_between_addresses("Edinburgh", "London", country="UK", mode="driving", units="imperial") self.assertIsNotNone(distance) self.assertIsInstance(distance, GoogleDistance) self.assertEquals("25.1 mi", distance._distance_text)
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)
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
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 execute(self, bot, clientid, data): logging.debug("GoogleMaps [%s]" % (data)) splits = data.split(" ") command = splits[0] from_place = splits[1] to_place = splits[2] googlemaps = GoogleMaps() if command == "DISTANCE": distance = googlemaps.get_distance_between_addresses( from_place, to_place) return self._format_distance_for_programy(distance) elif command == "DIRECTIONS": directions = googlemaps.get_directions_between_addresses( from_place, to_place) return self._format_directions_for_programy(directions) else: return None return "OK"
def execute(self, bot, clientid, data): if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug("GoogleMaps [%s]", data) splits = data.split(" ") command = splits[0] from_place = splits[1] to_place = splits[2] googlemaps = GoogleMaps(bot.license_keys) if command == "DISTANCE": distance = googlemaps.get_distance_between_addresses( from_place, to_place) return self._format_distance_for_programy(distance) elif command == "DIRECTIONS": directions = googlemaps.get_directions_between_addresses( from_place, to_place) return self._format_directions_for_programy(directions) else: if logging.getLogger().isEnabledFor(logging.ERROR): logging.error("Unknown Google Maps Extension command [%s]", command) return None
def test_directions(self): googlemaps = GoogleMaps(None) directions = googlemaps.get_directions_between_addresses("Edinburgh", "London") self.assertIsNotNone(directions) self.assertIsInstance(directions, GoogleDirections)
import os from programy.utils.text.text import TextUtils from programy.utils.geo.google import GoogleMaps from programy.utils.license.keys import LicenseKeys if __name__ == '__main__': license_keys = LicenseKeys() license_keys.load_license_key_file( os.path.dirname(__file__) + TextUtils.replace_path_seperator( '/../../../../bots/y-bot/config/license.keys')) # Only to be used to create test data for unit aiml_tests googlemaps = GoogleMaps(license_keys) # Running these tools drops test files into the geocode test folder googlemaps.store_get_latlong_for_location_to_file( "KY3 9UR", TextUtils.replace_path_seperator( "../../../test/utils/geo/google_latlong.json")) googlemaps.store_get_distance_between_addresses_as_file( "Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/geo/distance.json")) googlemaps.store_get_directions_between_addresses_as_file( "Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/geo/directions.json")) googlemaps.store_get_latlong_for_location_to_file(
def get_geo_locator(self): return GoogleMaps()
def get_geo_locator(self, context): return GoogleMaps()
def __init__(self, content): GoogleMaps.__init__(self) self._content = content
import os from programy.utils.text.text import TextUtils from programy.utils.geo.google import GoogleMaps from programy.utils.license.keys import LicenseKeys if __name__ == '__main__': license_keys = LicenseKeys() license_keys.load_license_key_file(os.path.dirname(__file__) + TextUtils.replace_path_seperator('/../../../../bots/y-bot/config/license.keys')) # Only to be used to create test data for unit aiml_tests googlemaps = GoogleMaps(license_keys) # Running these tools drops test files into the geocode test folder googlemaps.store_get_latlong_for_location_to_file("KY3 9UR", TextUtils.replace_path_seperator( "../../../test/utils/geo/google_latlong.json")) googlemaps.store_get_distance_between_addresses_as_file("Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/geo/distance.json")) googlemaps.store_get_directions_between_addresses_as_file("Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/geo/directions.json")) googlemaps.store_get_latlong_for_location_to_file("KY3 9UR", TextUtils.replace_path_seperator( "../../../test/utils/weather/google_latlong.json")) googlemaps.store_get_distance_between_addresses_as_file("Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/weather/distance.json")) googlemaps.store_get_directions_between_addresses_as_file("Edinburgh", "Kinghorn", TextUtils.replace_path_seperator( "../../../test/utils/weather/directions.json")) # Only to be used to create test data for unit aiml_tests