|
@ -38,6 +38,12 @@ def get_coordinates(city_name, country_code="US"): |
|
|
or None if the city is not found. |
|
|
or None if the city is not found. |
|
|
""" |
|
|
""" |
|
|
search_results = gc.search_cities(city_name, case_sensitive=True) |
|
|
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: |
|
|
if not search_results: |
|
|
return None |
|
|
return None |
|
|
populations = [city.get("population") for city in search_results] |
|
|
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) |
|
|
city1_coords = get_coordinates(city1, country1) |
|
|
city2_coords = get_coordinates(city2, country2) |
|
|
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 None |
|
|
|
|
|
|
|
|
return geodesic(city1_coords, city2_coords).km |
|
|
return geodesic(city1_coords, city2_coords).km |
|
|