From 3c9a54e0958e7c0341e470f508e5fbc6db920388 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Sat, 4 Feb 2023 20:23:14 +0100 Subject: sql-variables in common was stupid. put them where they are used --- scripts/tibber_consumption.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'scripts/tibber_consumption.py') 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) -- cgit v1.2.3