diff options
author | Dennis Eriksen <d@ennis.no> | 2023-02-01 20:59:42 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-02-01 20:59:42 +0100 |
commit | 7c403ecc8b6bd31f447eb91d73d95055489fbac4 (patch) | |
tree | f70a96871178c0d78be505cc71f090e4e91857ea | |
parent | moving and renaming/breaking everything (diff) | |
download | energyscripts-7c403ecc8b6bd31f447eb91d73d95055489fbac4.tar.gz |
fixing some lintingthings
-rw-r--r-- | scripts/common/__init__.py | 1 | ||||
-rw-r--r-- | scripts/common/queue.py | 2 | ||||
-rw-r--r-- | scripts/elvia.py | 9 | ||||
-rw-r--r-- | scripts/elvia_gridtariff.py | 6 | ||||
-rw-r--r-- | scripts/entsoe.py | 7 | ||||
-rw-r--r-- | scripts/mqtt_listener.py | 1 | ||||
-rw-r--r-- | scripts/nb.py | 17 | ||||
-rw-r--r-- | scripts/neohub.py | 3 | ||||
-rw-r--r-- | scripts/queue_runner.py | 8 | ||||
-rw-r--r-- | scripts/tibber_consumption.py | 4 | ||||
-rw-r--r-- | scripts/tibber_prices.py | 14 | ||||
-rw-r--r-- | scripts/yr.py | 4 |
12 files changed, 38 insertions, 38 deletions
diff --git a/scripts/common/__init__.py b/scripts/common/__init__.py index 89977d2..f6c02d3 100644 --- a/scripts/common/__init__.py +++ b/scripts/common/__init__.py @@ -3,7 +3,6 @@ import os - QUEUE = bool(os.environ.get('el_QUEUE', False)) # Initialize queue diff --git a/scripts/common/queue.py b/scripts/common/queue.py index e567fb4..cb90423 100644 --- a/scripts/common/queue.py +++ b/scripts/common/queue.py @@ -2,7 +2,6 @@ ''' common functions and stuff ''' import os -import sys import pickle from litequeue import SQLQueue @@ -12,6 +11,7 @@ QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db') q = SQLQueue(QUEUE_DB, maxsize=None) def dbi(sql,values,**kwargs): + ''' insert into queue ''' verbose = bool(kwargs['verbose']) if 'verbose' in kwargs else False q.put(pickle.dumps([sql, values])) diff --git a/scripts/elvia.py b/scripts/elvia.py index be5eaae..6e4bc9f 100644 --- a/scripts/elvia.py +++ b/scripts/elvia.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 -''' elvia2pgsql ''' +''' Get energy consumption from Elvia ''' import os import sys -import requests - from datetime import datetime from datetime import timedelta from tzlocal import get_localzone +import requests from common import dbi @@ -31,13 +30,13 @@ try: 'Authorization': "Bearer " + apiKey, } - response = requests.get(url, headers=hdr) + response = requests.get(url, headers=hdr, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) diff --git a/scripts/elvia_gridtariff.py b/scripts/elvia_gridtariff.py index bcf4bd7..28810b2 100644 --- a/scripts/elvia_gridtariff.py +++ b/scripts/elvia_gridtariff.py @@ -5,8 +5,8 @@ import os import sys from datetime import datetime from datetime import timedelta -import requests from tzlocal import get_localzone +import requests from common import dbi @@ -45,13 +45,13 @@ try: 'meteringPointIds': [ meteringPointId ] } - response = requests.post(url, headers=hdr, json=body) + response = requests.post(url, headers=hdr, json=body, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) diff --git a/scripts/entsoe.py b/scripts/entsoe.py index 2597a98..85785dc 100644 --- a/scripts/entsoe.py +++ b/scripts/entsoe.py @@ -1,4 +1,5 @@ -#!/bin/python3 +#!/usr/bin/env python3 +''' Get energyprices from Entsoe ''' import os import sys @@ -56,13 +57,13 @@ for area in areas: url = apiUrl + "&documentType=A44&in_Domain=" + area["code"] + "&out_Domain=" + area["code"] + "&periodStart=" + startTime + "0000&periodEnd=" + endTime + "0000" print("Getting data for " + area["code"]) - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() - except Exception as e: + except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) diff --git a/scripts/mqtt_listener.py b/scripts/mqtt_listener.py index 24ee207..6e9a307 100644 --- a/scripts/mqtt_listener.py +++ b/scripts/mqtt_listener.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +''' Listen for mqtt-events, and trigger for some ''' import os import json diff --git a/scripts/nb.py b/scripts/nb.py index 1901182..7cb753f 100644 --- a/scripts/nb.py +++ b/scripts/nb.py @@ -1,15 +1,14 @@ -#!/bin/python3 +#!/usr/bin/env python3 +''' Get exchange rates from nb ''' import os import sys import csv -import json -import requests import tempfile - from datetime import datetime from datetime import timedelta from tzlocal import get_localzone +import requests from common import dbi @@ -31,16 +30,16 @@ temp = tempfile.NamedTemporaryFile() try: url = apiUrl + "&startPeriod=" + startTime + "&endPeriod=" + endTime - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() - with open(temp.name,'w') as fd: + with open(temp.name,'w', encoding="utf-8") as fd: fd.write(response.text) -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) @@ -48,7 +47,7 @@ except Exception as e: ### insert data into database values = [] -with open(temp.name) as csvfile: +with open(temp.name, encoding="utf-8") as csvfile: csvReader = csv.DictReader(csvfile, delimiter=';') for item in csvReader: @@ -56,4 +55,4 @@ with open(temp.name) as csvfile: temp.close() -dbi("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s) ON CONFLICT (startdate,base_cur,quote_cur) DO NOTHING", values,verbose=True) +dbi("INSERT INTO " + pg_table + " VALUES(%s,%s,%s,%s) ON CONFLICT (startdate,base_cur,quote_cur) DO NOTHING", values, verbose=True) diff --git a/scripts/neohub.py b/scripts/neohub.py index 5c62606..7cc1160 100644 --- a/scripts/neohub.py +++ b/scripts/neohub.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +''' Get stuff from neohub! This is mostly the usage-example from https://gitlab.com/neohubapi/neohubapi/ ''' import os import asyncio @@ -11,6 +12,7 @@ neohub_ip = os.environ['el_neohub_ip'] neohub_port = os.environ['el_neohub_port'] async def run(): + ''' async runner! w00p ''' # Legacy connection hub = neohub.NeoHub(neohub_ip, int(neohub_port)) # Or, for a websocket connection: @@ -24,4 +26,3 @@ async def run(): dbi(sql, values) asyncio.run(run()) - diff --git a/scripts/queue_runner.py b/scripts/queue_runner.py index 436dcb8..fd4812e 100644 --- a/scripts/queue_runner.py +++ b/scripts/queue_runner.py @@ -19,7 +19,7 @@ con.commit() con.close() # Open Queue -q = SQLQueue(QUEUE_DB, maxsize=None) +q = SQLQueue(QUEUE_DB, maxsize=None) q.prune() msgids = [] @@ -30,7 +30,7 @@ i = 0 # Event loop while True: # Just sleep if queue is empty - if q.empty() == True: + if q.empty() is True: time.sleep(10) continue @@ -59,8 +59,8 @@ while True: dbi(sql,values) - for id in msgids: - q.done(id) + for msgid in msgids: + q.done(msgid) table = sql.split(' ')[2] num = 1 if isinstance(values, tuple) else len(values) diff --git a/scripts/tibber_consumption.py b/scripts/tibber_consumption.py index a411562..fa5169e 100644 --- a/scripts/tibber_consumption.py +++ b/scripts/tibber_consumption.py @@ -51,13 +51,13 @@ try: } } }"""} - response = requests.post(url, headers=hdr, json=body) + response = requests.post(url, headers=hdr, json=body, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) diff --git a/scripts/tibber_prices.py b/scripts/tibber_prices.py index 81b3afb..a2e9dda 100644 --- a/scripts/tibber_prices.py +++ b/scripts/tibber_prices.py @@ -34,11 +34,11 @@ try: 'Content-Type': 'application/json', } - body = {"query":"""{ - viewer { - homes { - currentSubscription{ - priceInfo{ + body = {"query":"""{ + viewer { + homes { + currentSubscription{ + priceInfo{ today { total energy tax startsAt level currency } tomorrow { total energy tax startsAt level currency } } @@ -46,13 +46,13 @@ try: } } }"""} - response = requests.post(url, headers=hdr, json=body) + response = requests.post(url, headers=hdr, json=body, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) diff --git a/scripts/yr.py b/scripts/yr.py index 9c3ae5e..3a6c8a7 100644 --- a/scripts/yr.py +++ b/scripts/yr.py @@ -26,13 +26,13 @@ try: 'Cache-Control': 'no-cache', } - response = requests.get(url, headers=hdr) + response = requests.get(url, headers=hdr, timeout=10) if response.status_code != 200: print(response.status_code) print("Oh shit") response.raise_for_status() -except Exception as e: +except requests.exceptions.RequestException as e: print("oh lol") sys.exit(e) |