aboutsummaryrefslogtreecommitdiffstats
path: root/todb.py
diff options
context:
space:
mode:
authordennis <d@ennis.no>2023-01-31 20:59:38 +0100
committerdennis <d@ennis.no>2023-01-31 20:59:38 +0100
commit3499ea624b67559f2c9530db4e36635106e22336 (patch)
treee2a81e6ed2368df7f538dacd479e3d2b5f4dba8a /todb.py
parenthandle HAN as well (diff)
downloadenergyscripts-3499ea624b67559f2c9530db4e36635106e22336.tar.gz
added queue, in case db-connection is down
Diffstat (limited to 'todb.py')
-rw-r--r--todb.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/todb.py b/todb.py
new file mode 100644
index 0000000..d911a29
--- /dev/null
+++ b/todb.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+
+import os
+import psycopg
+
+pg_db = os.environ['el_pg_db']
+pg_host = os.environ['el_pg_host']
+pg_user = os.environ['el_pg_user']
+pg_pass = os.environ['el_pg_pass']
+
+def todb(sql, values):
+ with psycopg.connect(dbname=pg_db, host=pg_host, user=pg_user, password=pg_pass) as conn:
+ if type(values) == list:
+ conn.executemany(sql, values)
+ elif type(values) == tuple:
+ conn.execute(sql, values)
+ else:
+ print("OH SHIT")
+ exit()