major bugfix

This commit is contained in:
mm 2023-05-05 03:34:56 +00:00
parent 8bd3e6f55e
commit 57ef4c06df
2 changed files with 8 additions and 2 deletions

View File

@ -24,7 +24,7 @@ def get_distance(city1, city2, country1="US", country2="US"):
city1_coords = get_coordinates(city1, country1)
city2_coords = get_coordinates(city2, country2)
if city1_coords is None or city2_coords is None:
if (city1_coords is None) or (city2_coords is None):
return None
return geodesic(city1_coords, city2_coords).km

View File

@ -38,6 +38,12 @@ def get_coordinates(city_name, country_code="US"):
or None if the city is not found.
"""
search_results = gc.search_cities(city_name, case_sensitive=True)
search_results = {
k: c
for k, c in search_results.items()
if (c.get("countrycode") == country_code)
}
if not search_results:
return None
populations = [city.get("population") for city in search_results]
@ -69,7 +75,7 @@ def get_distance(city1, city2, country1="US", country2="US"):
city1_coords = get_coordinates(city1, country1)
city2_coords = get_coordinates(city2, country2)
if city1_coords is None or city2_coords is None:
if (city1_coords is None) or (city2_coords is None):
return None
return geodesic(city1_coords, city2_coords).km