From bc9e6ab0963c6d50921f20ae959bf49b62e0d7b8 Mon Sep 17 00:00:00 2001 From: Edwin Eames Date: Fri, 9 May 2025 14:49:28 -0400 Subject: [PATCH] Removed try block due to error --- app/routers/main.py | 75 +++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/app/routers/main.py b/app/routers/main.py index cdbe846..8b15c2b 100644 --- a/app/routers/main.py +++ b/app/routers/main.py @@ -120,42 +120,45 @@ def update_temp(): if see_if_temp_exists is not None: return ({"ok": True}), 200 else: - temps = [] - - owm = OWM('21648d8c8d1a4ae495ace0b7810b4d36') - mgr = owm.weather_manager() - - # Search for current weather in London (Great Britain) and get details - observation = mgr.weather_at_place('Worcester, US') - w = observation.weather - - temp_dict_fahrenheit = w.temperature() # a dict in Kelvin units (default when no temperature units provided) - temp_dict_fahrenheit['temp_min'] - temp_dict_fahrenheit['temp_max'] - temp_dict_fahrenheit = w.temperature('fahrenheit') - - low_temp = temp_dict_fahrenheit['temp_min'] - high_temp = temp_dict_fahrenheit['temp_max'] - temps.append(temp_dict_fahrenheit['temp_max']) - temps.append(temp_dict_fahrenheit['temp_min']) - - get_avg = Average(temps) - rounded_temp = round(get_avg) - - dday = (65 - ((low_temp + high_temp) /2)) - - add_new_temp = Auto_Temp( - temp = temp_dict_fahrenheit['temp'], - temp_max = temp_dict_fahrenheit['temp_max'], - temp_min = temp_dict_fahrenheit['temp_min'], - temp_avg = rounded_temp, - degree_day = dday, - todays_date = date.today() - ) - - session.add(add_new_temp) - session.commit() + try: + temps = [] - return ({"ok": True}), 200 + owm = OWM('21648d8c8d1a4ae495ace0b7810b4d36') + mgr = owm.weather_manager() + + # Search for current weather in London (Great Britain) and get details + observation = mgr.weather_at_place('Worcester, US') + w = observation.weather + + temp_dict_fahrenheit = w.temperature() # a dict in Kelvin units (default when no temperature units provided) + temp_dict_fahrenheit['temp_min'] + temp_dict_fahrenheit['temp_max'] + temp_dict_fahrenheit = w.temperature('fahrenheit') + + low_temp = temp_dict_fahrenheit['temp_min'] + high_temp = temp_dict_fahrenheit['temp_max'] + temps.append(temp_dict_fahrenheit['temp_max']) + temps.append(temp_dict_fahrenheit['temp_min']) + + get_avg = Average(temps) + rounded_temp = round(get_avg) + + dday = (65 - ((low_temp + high_temp) /2)) + + add_new_temp = Auto_Temp( + temp = temp_dict_fahrenheit['temp'], + temp_max = temp_dict_fahrenheit['temp_max'], + temp_min = temp_dict_fahrenheit['temp_min'], + temp_avg = rounded_temp, + degree_day = dday, + todays_date = date.today() + ) + + session.add(add_new_temp) + session.commit() + + return ({"ok": True}), 200 + except: + return ({"ok": True}), 200 \ No newline at end of file