Skip to content
Draft
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
12 changes: 6 additions & 6 deletions apps/python-geoweather/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def get_public_ip():
return response.text.strip()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred: {http_err}') # HTTP error
return f"Unable to get public IP: HTTP error occurred: {http_err}"
return "Unable to get public IP due to an internal error."
except Exception as err:
logging.error(f'Other error occurred: {err}') # Other errors
return f"Unable to get public IP: Other error occurred: {err}"
return "Unable to get public IP due to an internal error."

def get_location(ip):
url = f"https://ipwho.is/{ip}?fields=country,city,latitude,longitude"
Expand All @@ -27,10 +27,10 @@ def get_location(ip):
return response.json()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred while fetching location: {http_err}')
return {'error': f"HTTP error occurred: {http_err}"}
return {'error': "Unable to fetch location due to an internal error."}
except Exception as err:
logging.error(f'Error fetching location: {err}')
return {'error': f"Other error occurred: {err}"}
return {'error': "Unable to fetch location due to an internal error."}

def get_weather(lat, lon):
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current=temperature_2m&forecast_days=1"
Expand All @@ -40,10 +40,10 @@ def get_weather(lat, lon):
return response.json()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred while fetching weather: {http_err}')
return {'error': f"HTTP error occurred: {http_err}"}
return {'error': "Unable to fetch weather due to an internal error."}
except Exception as err:
logging.error(f'Error fetching weather: {err}')
return {'error': f"Other error occurred: {err}"}
return {'error': "Unable to fetch weather due to an internal error."}

@app.route('/')
def index():
Expand Down