Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api.py #65

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

def get_coordinates(args):
"""
Takes a location(city or address) and returns the coordinates: [lat, long]
If no location is specified, default_location() finds the users coordinates
Takes a location (city or address) and returns the coordinates: [lat, long]
If no location is specified or the location is invalid, default_location()
finds the user's coordinates.
"""
for arg in args:
arg_str = str(arg)
Expand All @@ -27,13 +28,18 @@ def get_coordinates(args):
location = geolocator.geocode(address)
if location is not None:
return [location.latitude, location.longitude, location]
return "No data"
else:
print(
f"Invalid location '{address}' provided. "
"Using default location."
)
return default_location()
return default_location()


def default_location():
"""
If no location specified in cli, find users location
If no location specified in cli, find user's location
Make a GET request to the API endpoint
"""
response = requests.get("https://ipinfo.io/json", timeout=10)
Expand Down
Loading