aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/tibber_prices.py
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-02-04 20:23:14 +0100
committerDennis Eriksen <d@ennis.no>2023-02-04 20:23:21 +0100
commit3c9a54e0958e7c0341e470f508e5fbc6db920388 (patch)
tree3d9cb86bcb6454f6f615c5dc71388ac12c75c434 /scripts/tibber_prices.py
parentadding variable to env.sample (diff)
downloadenergyscripts-3c9a54e0958e7c0341e470f508e5fbc6db920388.tar.gz
sql-variables in common was stupid. put them where they are used
Diffstat (limited to 'scripts/tibber_prices.py')
-rw-r--r--scripts/tibber_prices.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/scripts/tibber_prices.py b/scripts/tibber_prices.py
index 985a068..05db9a5 100644
--- a/scripts/tibber_prices.py
+++ b/scripts/tibber_prices.py
@@ -63,9 +63,24 @@ print("Got " + str(numdata) + " rows from Tibber")
# prices
prices = []
for item in data["data"]["viewer"]["homes"][0]["currentSubscription"]["priceInfo"]["today"]:
- prices.append((item["startsAt"],item["total"],item["energy"],item["tax"],item["level"]))
+ prices.append((
+ item["startsAt"],
+ item["total"],
+ item["energy"],
+ item["tax"],
+ item["level"]))
for item in data["data"]["viewer"]["homes"][0]["currentSubscription"]["priceInfo"]["tomorrow"]:
- prices.append((item["startsAt"],item["total"],item["energy"],item["tax"],item["level"]))
-
-common.dbi(common.sql[common.name], prices, verbose=True)
+ prices.append((
+ item["startsAt"],
+ item["total"],
+ item["energy"],
+ item["tax"],
+ item["level"]))
+
+# SQL
+sql = """ INSERT INTO tibber_prices
+ VALUES(%s, %s, %s, %s, %s)
+ ON CONFLICT (startsat) DO NOTHING""",
+
+common.dbi(sql, prices, verbose=True)