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.py8
1 files changed, 2 insertions, 6 deletions
diff --git a/scripts/tibber_consumption.py b/scripts/tibber_consumption.py
index fa5169e..ea38bcb 100644
--- a/scripts/tibber_consumption.py
+++ b/scripts/tibber_consumption.py
@@ -8,17 +8,13 @@ from datetime import timedelta
from tzlocal import get_localzone
import requests
-from common import dbi
+import common
# variables
apiKey = os.environ['el_tibber_token']
apiUrl = "https://api.tibber.com/v1-beta/gql"
-pg_db = os.environ['el_pg_db']
-pg_host = os.environ['el_pg_host']
-pg_table = "tibber_consumption"
-
startTime = datetime.now(get_localzone()) - timedelta(days = 1)
startTime = startTime.isoformat('T')
@@ -73,4 +69,4 @@ 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"]))
-dbi("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT (startTime,endTime) DO NOTHING", values, verbose=True)
+common.dbi(common.sql[common.name], values, verbose=True)