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_prices.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'scripts/tibber_prices.py') 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) -- cgit v1.2.3