return location always

This commit is contained in:
Daniel Tsvetkov 2020-04-23 13:39:35 +02:00
parent 85fcf2d6b5
commit 8430260527

View File

@ -38,12 +38,12 @@ DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S%z'
basepath = os.path.dirname(os.path.abspath(__file__)) basepath = os.path.dirname(os.path.abspath(__file__))
class Location: class Location(object):
""" """
Represents a location with name, latitude and longitude Represents a location with name, latitude and longitude
""" """
def __init__(self, name: str, latitude: float, longitude: float): def __init__(self, name: str = None, latitude: float = 0.0, longitude: float = 0.0):
self.name = name self.name = name
self.latitude = latitude self.latitude = latitude
self.longitude = longitude self.longitude = longitude
@ -180,10 +180,12 @@ def resolve_location_remote(query):
geolocator = Nominatim(user_agent=user_agent) geolocator = Nominatim(user_agent=user_agent)
try: try:
location = geolocator.geocode(query) location = geolocator.geocode(query)
write_to_cache(query, location) if location:
return location write_to_cache(query, location)
return location
except GeocoderTimedOut: except GeocoderTimedOut:
logger.info("Timed out resolving location. Try specifying a timezone directly") logger.info("Timed out resolving location. Try specifying a timezone directly")
return Location()
def parse_query(query): def parse_query(query):