diff options
author | Dennis Eriksen <d@ennis.no> | 2023-02-04 20:23:14 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-02-04 20:23:21 +0100 |
commit | 3c9a54e0958e7c0341e470f508e5fbc6db920388 (patch) | |
tree | 3d9cb86bcb6454f6f615c5dc71388ac12c75c434 /scripts/yr.py | |
parent | adding variable to env.sample (diff) | |
download | energyscripts-3c9a54e0958e7c0341e470f508e5fbc6db920388.tar.gz |
sql-variables in common was stupid. put them where they are used
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) |