Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_location_ne(self):
"""
Location.__ne__
"""
loc1 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
loc2 = Location(GRAND_CENTRAL_STR, None)
self.assertNotEqual(loc1, loc2)
"""
Parse each record.
"""
try:
place = place['GeoObject']
except KeyError:
raise GeocoderParseError('Failed to parse server response')
longitude, latitude = [
float(_) for _ in place['Point']['pos'].split(' ')
]
name_elements = ['name', 'description']
location = ', '.join([place[k] for k in name_elements if place.get(k)])
return Location(location, (latitude, longitude), place)
location = "%s %s" % (
place.get('postal_code', ''),
place.get('commune', ''),
)
if place.get('street'):
location = "%s, %s" % (
place.get('street', ''),
location,
)
if place.get('building'):
location = "%s %s" % (
place.get('building', ''),
location,
)
return Location(location, (place.get('lat'), place.get('lng')), place)
def parse_code(place):
# TODO make this a private API
# Parse each resource.
latitude = place.get('lat', None)
longitude = place.get('lon', None)
placename = place.get('display_name', None)
if latitude is not None and longitude is not None:
latitude = float(latitude)
longitude = float(longitude)
return Location(placename, (latitude, longitude), place)
def parse_place(place):
'''Get the location, lat, lon from a single json result.'''
location = place.get('description')
latitude = place.get('lat')
longitude = place.get('lon')
return Location(location, (latitude, longitude), place)
def parse_place(place):
'''Get the location, lat, lng from a single json place.'''
location = place.get('formatted')
latitude = place['geometry']['lat']
longitude = place['geometry']['lng']
return Location(location, (latitude, longitude), place)
def _parse_feature(feature):
# Parse each resource.
latitude = feature.get('geometry', {}).get('coordinates', [])[1]
longitude = feature.get('geometry', {}).get('coordinates', [])[0]
placename = feature.get('properties', {}).get('label')
return Location(placename, (latitude, longitude), feature)
longitude = place.get('lng', None)
if latitude and longitude:
latitude = float(latitude)
longitude = float(longitude)
else:
return None
placename = place.get('name')
state = place.get('adminName1', None)
country = place.get('countryName', None)
location = ', '.join(
[x for x in [placename, state, country] if x]
)
return Location(location, (latitude, longitude), place)