diff options
Diffstat (limited to 'scripts/yr.py')
-rw-r--r-- | scripts/yr.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/scripts/yr.py b/scripts/yr.py index deb248b..f6b654c 100644 --- a/scripts/yr.py +++ b/scripts/yr.py @@ -40,6 +40,25 @@ data = response.json() values = [] for item in data["properties"]["timeseries"]: details = item["data"]["instant"]["details"] - values.append((item["time"],details["air_temperature"],details["air_pressure_at_sea_level"],details["cloud_area_fraction"],details["relative_humidity"],details["wind_from_direction"],details["wind_speed"])) + values.append(( + item["time"], + details["air_temperature"], + details["air_pressure_at_sea_level"], + details["cloud_area_fraction"], + details["relative_humidity"], + details["wind_from_direction"], + details["wind_speed"])) -common.dbi(common.sql[common.name], values, verbose=True) +# SQL +sql = """ INSERT INTO yr + VALUES(%s, %s, %s, %s, %s, %s, %s) + ON CONFLICT (time) DO UPDATE SET + air_temperature=EXCLUDED.air_temperature, + air_pressure_at_sea_level=EXCLUDED.air_pressure_at_sea_level, + cloud_area_fraction=EXCLUDED.cloud_area_fraction, + relative_humidity=EXCLUDED.relative_humidity, + wind_from_direction=EXCLUDED.wind_from_direction, + wind_speed=EXCLUDED.wind_speed, + updated=now()""" + +common.dbi(sql, values, verbose=True) |