diff options
author | Dennis Eriksen <d@ennis.no> | 2023-11-02 12:49:02 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-11-02 12:49:02 +0100 |
commit | b322330b000a6d566e99cde1c29429a23b5f2cb3 (patch) | |
tree | e6c6b646869e853de4dd9179d5c6f5a5ce5bc153 /scripts/common/postgres.py | |
parent | adding linting with ruff (diff) | |
download | energyscripts-b322330b000a6d566e99cde1c29429a23b5f2cb3.tar.gz |
adding formatting with ruff
Diffstat (limited to 'scripts/common/postgres.py')
-rw-r--r-- | scripts/common/postgres.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/scripts/common/postgres.py b/scripts/common/postgres.py index efa4b5a..5f6ea31 100644 --- a/scripts/common/postgres.py +++ b/scripts/common/postgres.py @@ -1,28 +1,31 @@ #!/usr/bin/env python3 -''' common functions and stuff ''' +""" 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','') +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 + """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: + 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') + 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 in db") |