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/elvia.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'scripts/elvia.py') diff --git a/scripts/elvia.py b/scripts/elvia.py index 2248238..61bc692 100644 --- a/scripts/elvia.py +++ b/scripts/elvia.py @@ -47,8 +47,18 @@ values = [] for item in data['meteringpoints'][0]['metervalue']['timeSeries']: # Only deal with verified items. if item['verified']: - values.append((data['meteringpoints'][0]['meteringPointId'], item['startTime'], item['endTime'], item['value'], item['uom'], item['production'])) + values.append(( + data['meteringpoints'][0]['meteringPointId'], + item['startTime'], + item['endTime'], + item['value'], + item['uom'], + item['production'])) -# Count new rows and insert -common.dbi(common.sql[common.name], values, verbose=True) +# SQL +sql = """ INSERT INTO elvia + VALUES(%s, %s, %s, %s, %s, %s) + ON CONFLICT (startTime,endTime) DO NOTHING;""" + +common.dbi(sql, values, verbose=True) -- cgit v1.2.3