diff --git a/apps/python-geoweather/app.py b/apps/python-geoweather/app.py index 68ff862..9e2c160 100644 --- a/apps/python-geoweather/app.py +++ b/apps/python-geoweather/app.py @@ -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" @@ -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}¤t=temperature_2m&forecast_days=1" @@ -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(): @@ -69,15 +69,15 @@ def weather(): public_ip = get_public_ip() if "Unable to get public IP" in public_ip: - return f"
Error: {public_ip}
" + return "Error: Unable to get public IP due to an internal error.
" location = get_location(public_ip) if 'error' in location: - return f"Error fetching location data for IP {public_ip}: {location['error']}
" + return "Error fetching location data due to an internal error.
" weather = get_weather(location['latitude'], location['longitude']) if 'error' in weather: - return f"Error fetching weather data: {weather['error']}
" + return "Error fetching weather data due to an internal error.
" weather_html = f"""