major claude changes

This commit is contained in:
2026-01-28 21:54:58 -05:00
parent 6316309184
commit ac4354716b
15 changed files with 269 additions and 95 deletions

View File

@@ -1,7 +1,10 @@
import logging
from datetime import date
import requests
from decimal import Decimal
logger = logging.getLogger(__name__)
# Import your database model and the session from your database configuration
from app.models.auto import Auto_Temp
from database import session
@@ -22,11 +25,11 @@ def fetch_and_store_daily_temp() -> bool:
# 1. Check if the temperature for today already exists in the database
today = date.today()
if session.query(Auto_Temp).filter(Auto_Temp.todays_date == today).first():
print(f"Temperature for {today} already exists in the database. Skipping fetch.")
logger.info(f"Temperature for {today} already exists in the database. Skipping fetch.")
return True
# 2. If it doesn't exist, fetch it from the API
print(f"Fetching temperature for {today} from OpenWeatherMap...")
logger.info(f"Fetching temperature for {today} from OpenWeatherMap...")
try:
# API key and location
api_key = '21648d8c8d1a4ae495ace0b7810b4d36'
@@ -63,11 +66,11 @@ def fetch_and_store_daily_temp() -> bool:
# 4. Add the new record to the session (it will be committed by the calling function)
session.add(add_new_temp)
print(f"Successfully fetched and staged temperature for {today}.")
logger.info(f"Successfully fetched and staged temperature for {today}.")
return True
except Exception as e:
print(f"An error occurred while fetching weather data: {e}")
logger.info(f"An error occurred while fetching weather data: {e}")
# Make sure to rollback the session in case of a partial failure
session.rollback()
return False