aboutsummaryrefslogblamecommitdiffstats
path: root/todb.py
blob: 7426aced6c41ebebb74a9d49d97ec99378ff82af (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                                             

                                        
                               

                                     
                    


                            
#!/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:
            cur = conn.cursor()
            cur.executemany(sql, values)
            return cur.rowcount
        elif type(values) == tuple: 
            conn.execute(sql, values)
            return 1
        else:
            print("OH SHIT")
            exit()