Skip to content

Instantly share code, notes, and snippets.

View schnipdip's full-sized avatar

schnipdip

View GitHub Profile
@schnipdip
schnipdip / python.py
Created September 19, 2020 15:22
Constructing #Postgresql connection obect
import psycopg2
def connect_postgres():
#get configparser
config = get_configParser()
#import configuration information to connect to remote postrgre database
postgresServer = config['database_postgres']['postgres_server']
postgrestPort = config['database_postgres']['postgres_port']
postgresDatabase = config['database_postgres']['postgres_database']
@schnipdip
schnipdip / python.py
Last active September 19, 2020 15:29
Creating a #Postgresql Table
import psycopg2
def create_table():
#Referece: Constructing #Postgresql connection obect
sql_create_asset_table = ('''CREATE TABLE IF NOT EXISTS ASSETS (
ID SERIAL PRIMARY KEY,
NAME TEXT NOT NULL,
LICENSE TEXT NOT NULL,
@schnipdip
schnipdip / python.py
Created September 19, 2020 15:32
Inserting Objects to #Postgresql Database
import psycopg2
def insert_object():
#Referece: Constructing #Postgresql connection obect
cursor.execute("""INSERT INTO TABLENAME(COLUMNS)\
VALUES (%s)""",(OBJECT))
conn.commit()
@schnipdip
schnipdip / python.py
Last active September 19, 2020 16:19
Generator Objects
'''
Generator functions allow you to declare a function that behaves like an iterator, i.e. it can be used in a for loop.
Objects are not stored in memory.
'''
def generator_function():
counter = 0
x = 10
while counter < x: