diff --git a/debug_distance.py b/debug_distance.py index d0123c6..7e391e2 100644 --- a/debug_distance.py +++ b/debug_distance.py @@ -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 diff --git a/generate_data.py b/generate_data.py index d0656f2..b16f3e4 100644 --- a/generate_data.py +++ b/generate_data.py @@ -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