feat: Added travel deletion and added ability to add locations

This commit is contained in:
ITQ
2024-03-25 02:51:25 +03:00
parent dd16eda94a
commit 65719a61ef
9 changed files with 520 additions and 42 deletions
+22 -1
View File
@@ -1,5 +1,5 @@
# type: ignore
__all__ = ("validate_country", "validate_city")
__all__ = ("validate_country", "validate_city", "get_location_by_name")
from geopy.exc import GeocoderTimedOut
from geopy.geocoders import Nominatim
@@ -72,3 +72,24 @@ def validate_city(city: str, country: str):
return True, normalized_country
return False, None
def get_location_by_name(location: str) -> None:
geolocator = Nominatim(user_agent="travel_agent_bot")
for _ in range(3):
try:
geocode = geolocator.geocode(
location,
featuretype="city",
)
break
except GeocoderTimedOut:
continue
else:
return False, None
if not geocode:
return False, None
return True, geocode