diff options
Diffstat (limited to '')
-rw-r--r-- | scripts/common/__init__.py (renamed from common/__init__.py) | 0 | ||||
-rw-r--r-- | scripts/common/postgres.py (renamed from common/postgres.py) | 0 | ||||
-rw-r--r-- | scripts/common/queue.py (renamed from common/queue.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/elvia.py (renamed from elvia2pgsql.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/elvia_gridtariff.py (renamed from elvia_gridtariff2pgsql.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/entsoe.py (renamed from entsoe2pgsql.py) | 0 | ||||
-rw-r--r-- | scripts/mqtt_listener.py (renamed from mqtt2queue.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/nb.py (renamed from nb2pgsql.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/neohub.py (renamed from neohub2pgsql.py) | 0 | ||||
-rw-r--r-- | scripts/queue_runner.py (renamed from queue2pgsql.py) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/tibber_consumption.py (renamed from tibber_consumption2pgsql.py) | 44 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/tibber_prices.py (renamed from tibber_prices2pgsql.py) | 39 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/yr.py (renamed from yr2pgsql.py) | 0 |
13 files changed, 15 insertions, 68 deletions
diff --git a/common/__init__.py b/scripts/common/__init__.py index 89977d2..89977d2 100644 --- a/common/__init__.py +++ b/scripts/common/__init__.py diff --git a/common/postgres.py b/scripts/common/postgres.py index bff0720..bff0720 100644 --- a/common/postgres.py +++ b/scripts/common/postgres.py diff --git a/common/queue.py b/scripts/common/queue.py index e567fb4..e567fb4 100644 --- a/common/queue.py +++ b/scripts/common/queue.py diff --git a/elvia2pgsql.py b/scripts/elvia.py index be5eaae..be5eaae 100755..100644 --- a/elvia2pgsql.py +++ b/scripts/elvia.py diff --git a/elvia_gridtariff2pgsql.py b/scripts/elvia_gridtariff.py index bcf4bd7..bcf4bd7 100755..100644 --- a/elvia_gridtariff2pgsql.py +++ b/scripts/elvia_gridtariff.py diff --git a/entsoe2pgsql.py b/scripts/entsoe.py index 2597a98..2597a98 100755..100644 --- a/entsoe2pgsql.py +++ b/scripts/entsoe.py diff --git a/mqtt2queue.py b/scripts/mqtt_listener.py index 24ee207..24ee207 100644 --- a/mqtt2queue.py +++ b/scripts/mqtt_listener.py diff --git a/nb2pgsql.py b/scripts/nb.py index 1901182..1901182 100755..100644 --- a/nb2pgsql.py +++ b/scripts/nb.py diff --git a/neohub2pgsql.py b/scripts/neohub.py index 5c62606..5c62606 100755..100644 --- a/neohub2pgsql.py +++ b/scripts/neohub.py diff --git a/queue2pgsql.py b/scripts/queue_runner.py index 436dcb8..436dcb8 100644 --- a/queue2pgsql.py +++ b/scripts/queue_runner.py diff --git a/tibber_consumption2pgsql.py b/scripts/tibber_consumption.py index e710b8f..a411562 100755..100644 --- a/tibber_consumption2pgsql.py +++ b/scripts/tibber_consumption.py @@ -1,14 +1,14 @@ -#!/bin/python3 +#!/usr/bin/env python3 +''' import energy consumption from tibber ''' import os import sys -import json -import psycopg2 -import requests - from datetime import datetime from datetime import timedelta from tzlocal import get_localzone +import requests + +from common import dbi # variables @@ -34,9 +34,9 @@ try: 'Content-Type': 'application/json', } - body = {"query":"""{ - viewer { - homes { + body = {"query":"""{ + viewer { + homes { consumption(resolution: HOURLY, last:100) { nodes { from @@ -73,30 +73,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"])) -# connect to db -conn = psycopg2.connect(database=pg_db, host=pg_host) -cur = conn.cursor() - -# count rows before we start -cur.execute("SELECT COUNT(*) FROM " + pg_table) -before = cur.fetchone() - -# insert data -try: - cur.executemany("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT (startTime,endTime) DO NOTHING", values) - conn.commit() -except Exception as e: - conn.rollback() - raise e - -# count rows after we finnish -cur.execute("SELECT COUNT(*) FROM " + pg_table) -after = cur.fetchone() - -# count *new* rows -newRows = after[0] - before[0] - -# close connection -conn.close() - -print("Successfully inserted " + str(newRows) + " records into the database") +dbi("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT (startTime,endTime) DO NOTHING", values, verbose=True) diff --git a/tibber_prices2pgsql.py b/scripts/tibber_prices.py index 046072f..81b3afb 100755..100644 --- a/tibber_prices2pgsql.py +++ b/scripts/tibber_prices.py @@ -1,14 +1,14 @@ -#!/bin/python3 +#!/usr/bin/env python3 +''' import energy prices from tibber ''' import os import sys -import json -import psycopg2 -import requests - from datetime import datetime from datetime import timedelta from tzlocal import get_localzone +import requests + +from common import dbi # variables @@ -73,31 +73,4 @@ for item in data["data"]["viewer"]["homes"][0]["currentSubscription"]["priceInfo prices.append((item["startsAt"],item["total"],item["energy"],item["tax"],item["level"])) -# connect to db -conn = psycopg2.connect(database=pg_db, host=pg_host) -cur = conn.cursor() - -# count rows before we start -cur.execute("SELECT COUNT(*) FROM " + pg_table) -before = cur.fetchone() - -# insert data -try: - cur.executemany("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s,%s) ON CONFLICT (startsat) DO NOTHING", prices) - conn.commit() -except Exception as e: - conn.rollback() - raise e - -# count rows after we finnish -cur.execute("SELECT COUNT(*) FROM " + pg_table) -after = cur.fetchone() - -# count *new* rows -newRows = after[0] - before[0] - -# close connection -conn.close() - - -print("Successfully inserted " + str(newRows) + " records into the database") +dbi("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s,%s) ON CONFLICT (startsat) DO NOTHING", prices, verbose=True) diff --git a/yr2pgsql.py b/scripts/yr.py index 9c3ae5e..9c3ae5e 100755..100644 --- a/yr2pgsql.py +++ b/scripts/yr.py |