Round floats to ints, tweak template, traceback

This commit is contained in:
Evan 2025-01-22 21:33:20 -05:00
parent eb57844621
commit 054d4aaba4

View file

@ -5,12 +5,13 @@ import logging
import re
import typing as t
import requests
import traceback
import models
from config import env_OWM_KEY, env_OWM_UNITS
logger = logging.getLogger("gunicorn.error")
weather_template = "The current temperature is {0} and feels like {1}. The high today is {2} with a low of {3}. The current humidity is {4} percent. The summary for today is: {5}."
weather_template = "The current temperature is: {0}. The real feel temperature is: {1}. The high is: {2}. The low is: {3}. The current humidity is: {4} percent. The summary for today is: {5}."
def str_none(x):
@ -65,16 +66,17 @@ def _get_weather(lat, long):
return "An error has occured and the weather could not be retrieved."
weather = weather_template.format(
weather_json["current"]["temp"],
weather_json["current"]["feels_like"],
weather_json["daily"][0]["temp"]["max"],
weather_json["daily"][0]["temp"]["min"],
weather_json["current"]["humidity"],
round(weather_json["current"]["temp"]),
round(weather_json["current"]["feels_like"]),
round(weather_json["daily"][0]["temp"]["max"]),
round(weather_json["daily"][0]["temp"]["min"]),
round(weather_json["current"]["humidity"]),
weather_json["daily"][0]["summary"],
)
return weather
except Exception as e:
logger.error("Error in _get_weather: " + str(e))
logger.error(traceback.format_exc())
return "An error has occured and the weather could not be retrieved."
@ -94,6 +96,7 @@ def _get_weather_json(lat, long):
return None
except requests.exceptions.RequestException as e:
logger.error("Error in _get_weather_json: " + str(e))
logger.error(traceback.format_exc())
return None
@ -114,4 +117,5 @@ def _get_cords(zipcode):
return None, None
except requests.exceptions.RequestException as e:
logger.error("Error in _get_cords: " + str(e))
logger.error(traceback.format_exc())
return None, None