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/tibber_consumption.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/tibber_consumption.py')
-rw-r--r-- | scripts/tibber_consumption.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/tibber_consumption.py b/scripts/tibber_consumption.py index ea38bcb..3df48fe 100644 --- a/scripts/tibber_consumption.py +++ b/scripts/tibber_consumption.py @@ -67,6 +67,18 @@ print("Got " + str(numdata) + " rows from Tibber") values = [] for item in data["data"]["viewer"]["homes"][0]["consumption"]["nodes"]: if item["consumption"] is not None: - values.append((item["from"],item["to"],item["consumption"],item["consumptionUnit"],item["cost"],item["unitPrice"],item["unitPriceVAT"])) + values.append(( + item["from"], + item["to"], + item["consumption"], + item["consumptionUnit"], + item["cost"], + item["unitPrice"], + item["unitPriceVAT"])) -common.dbi(common.sql[common.name], values, verbose=True) +# SQL +sql = """ INSERT INTO tibber_consumption + VALUES(%s, %s, %s, %s, %s, %s, %s) + ON CONFLICT (startTime,endTime) DO NOTHING""" + +common.dbi(sql, values, verbose=True) |