Auto-update: Tue Aug 6 21:36:05 PDT 2024

This commit is contained in:
sanj 2024-08-06 21:36:05 -07:00
parent e073efb0fa
commit e878406e3c

View file

@ -199,8 +199,8 @@ async def store_weather_to_db(date_time: dt_datetime, weather_data: dict):
RETURNING id RETURNING id
''' '''
await API.execute_write_query(daily_weather_query, *daily_weather_params, table_name="dailyweather") daily_weather_id = await API.execute_write_query(daily_weather_query, *daily_weather_params, table_name="dailyweather")
debug(f"Inserted daily weather data") debug(f"Inserted daily weather data with id: {daily_weather_id}")
if 'hours' in day_data: if 'hours' in day_data:
debug(f"Processing {len(day_data['hours'])} hourly records") debug(f"Processing {len(day_data['hours'])} hourly records")
@ -210,7 +210,7 @@ async def store_weather_to_db(date_time: dt_datetime, weather_data: dict):
hour_preciptype_array = hour_data.get('preciptype', []) or [] hour_preciptype_array = hour_data.get('preciptype', []) or []
hour_stations_array = hour_data.get('stations', []) or [] hour_stations_array = hour_data.get('stations', []) or []
hourly_weather_params = [ hourly_weather_params = [
date_time, # Use the daily weather datetime as a foreign key daily_weather_id, # Use the daily weather id as a foreign key
hour_data['datetime'], hour_data['datetime'],
hour_data.get('datetimeEpoch'), hour_data.get('datetimeEpoch'),
hour_data['temp'], hour_data['temp'],
@ -242,7 +242,7 @@ async def store_weather_to_db(date_time: dt_datetime, weather_data: dict):
hourly_weather_params = ['' if v is None else v for v in hourly_weather_params] hourly_weather_params = ['' if v is None else v for v in hourly_weather_params]
hourly_weather_query = ''' hourly_weather_query = '''
INSERT INTO hourlyweather (daily_weather_datetime, datetime, datetimeepoch, temp, feelslike, humidity, dew, precip, precipprob, INSERT INTO hourlyweather (daily_weather_id, datetime, datetimeepoch, temp, feelslike, humidity, dew, precip, precipprob,
preciptype, snow, snowdepth, windgust, windspeed, winddir, pressure, cloudcover, visibility, solarradiation, solarenergy, preciptype, snow, snowdepth, windgust, windspeed, winddir, pressure, cloudcover, visibility, solarradiation, solarenergy,
uvindex, severerisk, conditions, icon, stations, source) uvindex, severerisk, conditions, icon, stations, source)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)