Beispiel #1
0
    def test_latlong(self):

        latlong = LatLong(latitude=1.0, longitude=2.0)
        self.assertIsNotNone(latlong)
        self.assertEqual(1.0, latlong.latitude)
        self.assertEqual(2.0, latlong.longitude)

        self.assertEqual("Latitude: 1.00, Longitude: 2.00", latlong.to_string())
Beispiel #2
0
    def test_latlong(self):

        latlong = LatLong(latitude=1.0, longitude=2.0)
        self.assertIsNotNone(latlong)
        self.assertEquals(1.0, latlong.latitude)
        self.assertEquals(2.0, latlong.longitude)

        self.assertEquals("Latitude: 1.00, Longitude: 2.00", latlong.to_string())
Beispiel #3
0
    def get_latlong_for_postcode(self, postcode):

        if GeoNamesApi.get_latlong_for_postcode_response_file is None:
            data = self._get_latlong_for_postcode_response(postcode)
        else:
            try:
                with open(GeoNamesApi.get_latlong_for_postcode_response_file,
                          "r",
                          encoding="utf-8") as datafile:
                    data = json.load(datafile)
            except FileNotFoundError:
                YLogger.error(
                    self, "File not found [%s]",
                    GeoNamesApi.get_latlong_for_postcode_response_file)

        if 'postalCodes' not in data:
            raise Exception("Invalid/Unknown post code")
        if not data['postalCodes']:
            raise Exception("Invalid/Unknown post code")
        if 'lat' not in data['postalCodes'][0] or 'lng' not in data[
                'postalCodes'][0]:
            raise Exception("Invalid/Unknown post code")

        return LatLong(data['postalCodes'][0]['lat'],
                       data['postalCodes'][0]['lng'])
Beispiel #4
0
 def parse_json(self, data):
     self.location_type = data['location_type']
     self.location = LatLong(data['location']['lat'], data['location']['lng'])
     self.bounds = GoogleBounds()
     self.bounds.parse_json(data['bounds'])
     self.viewport = GoogleBounds()
     self.viewport.parse_json(data['bounds'])
Beispiel #5
0
    def get_latlong_for_postcode(self, postcode):

        url = self._format_url(postcode)

        data = self._get_latlong_for_postcode_response(url)

        if 'postalCodes' not in data:
            raise Exception("Invalid/Unknown post code")

        if not data['postalCodes']:
            raise Exception("Invalid/Unknown post code")

        if 'lat' not in data['postalCodes'][0] or 'lng' not in data[
                'postalCodes'][0]:
            raise Exception("Invalid/Unknown post code")

        return LatLong(data['postalCodes'][0]['lat'],
                       data['postalCodes'][0]['lng'])
Beispiel #6
0
    def get_latlong_for_postcode(self, postcode):

        if GeoNamesApi.get_latlong_for_postcode_response_file is None:
            data = self._get_latlong_for_postcode_response(postcode)
        else:
            with open(GeoNamesApi.get_latlong_for_postcode_response_file,
                      "r+") as datafile:
                data = json.load(datafile)

        if 'postalCodes' not in data:
            raise Exception("Invalid/Unknown post code")
        if len(data['postalCodes']) == 0:
            raise Exception("Invalid/Unknown post code")
        if 'lat' not in data['postalCodes'][0] or 'lng' not in data[
                'postalCodes'][0]:
            raise Exception("Invalid/Unknown post code")

        return LatLong(data['postalCodes'][0]['lat'],
                       data['postalCodes'][0]['lng'])
Beispiel #7
0
 def parse_json(self, data):
     self.northeast = LatLong(data['northeast']['lat'],
                              data['northeast']['lng'])
     self.southwest = LatLong(data['southwest']['lat'],
                              data['southwest']['lng'])