aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-02-01 20:32:11 +0100
committerDennis Eriksen <d@ennis.no>2023-02-01 20:32:11 +0100
commit8d186d39483beff64a1c11f80c6ca5e56dd7bbc5 (patch)
tree2c5a64ace4bd8eabd4d65014c5313bd7edd76191 /common
parentrun queue in batches (diff)
downloadenergyscripts-8d186d39483beff64a1c11f80c6ca5e56dd7bbc5.tar.gz
moving and renaming/breaking everything
Diffstat (limited to 'common')
-rw-r--r--common/__init__.py13
-rw-r--r--common/postgres.py28
-rw-r--r--common/queue.py22
3 files changed, 0 insertions, 63 deletions
diff --git a/common/__init__.py b/common/__init__.py
deleted file mode 100644
index 89977d2..0000000
--- a/common/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env python3
-''' common functions and stuff '''
-
-import os
-
-
-QUEUE = bool(os.environ.get('el_QUEUE', False))
-
-# Initialize queue
-if QUEUE is True:
- from .queue import dbi
-else:
- from .postgres import dbi
diff --git a/common/postgres.py b/common/postgres.py
deleted file mode 100644
index bff0720..0000000
--- a/common/postgres.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env python3
-''' common functions and stuff '''
-
-import os
-import sys
-import psycopg
-
-pg_db = os.environ['el_pg_db']
-pg_host = os.environ['el_pg_host']
-pg_user = os.environ.get('el_pg_user','')
-pg_pass = os.environ.get('el_pg_pass','')
-
-def dbi(sql, values, **kwargs):
- ''' insert into db '''
- verbose = bool(kwargs['verbose']) if 'verbose' in kwargs else False
- # pylint: disable=E1129
- with psycopg.connect(dbname=pg_db, host=pg_host, user=pg_user, password=pg_pass) as conn:
- cur = conn.cursor()
- if isinstance(values, list):
- cur.executemany(sql, values)
- elif isinstance(values, tuple):
- cur.execute(sql, values)
- else:
- print('`values` is a', type(values), 'but it needs to be tuple or list')
- sys.exit(1)
- if verbose is True:
- print("Inserted and/or changed", cur.rowcount, "rows into db")
- return True
diff --git a/common/queue.py b/common/queue.py
deleted file mode 100644
index e567fb4..0000000
--- a/common/queue.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env python3
-''' common functions and stuff '''
-
-import os
-import sys
-import pickle
-from litequeue import SQLQueue
-
-QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
-
-# Initialize queue
-q = SQLQueue(QUEUE_DB, maxsize=None)
-
-def dbi(sql,values,**kwargs):
- verbose = bool(kwargs['verbose']) if 'verbose' in kwargs else False
-
- q.put(pickle.dumps([sql, values]))
- if verbose is True:
- table = sql.split(' ')[2]
- num = 1 if isinstance(values, tuple) else len(values)
- print("Inserted", num, "item(s) into queue for", table)
- return True