aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/tibber_consumption.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/tibber_consumption.py')
-rw-r--r--scripts/tibber_consumption.py16
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)