import psycopg2 import sys from dj_database_url import config as get_db_config # Parse the database configuration into something psycopg2 can handle raw_dbconfig = get_db_config(default='postgres://hurley@localhost/cacheusage') dbconfig = {} if raw_dbconfig['NAME']: dbconfig['database'] = raw_dbconfig['NAME'] if raw_dbconfig['USER']: dbconfig['user'] = raw_dbconfig['USER'] if raw_dbconfig['PASSWORD']: dbconfig['password'] = raw_dbconfig['PASSWORD'] if raw_dbconfig['HOST']: dbconfig['host'] = raw_dbconfig['HOST'] if raw_dbconfig['PORT']: dbconfig['port'] = raw_dbconfig['port'] def get_conn(): return psycopg2.connect(**dbconfig) if __name__ == '__main__': conn = get_conn() cur = conn.cursor() if sys.argv[1] == 'create': cur.execute("SELECT * from pg_catalog.pg_tables " "WHERE tablename = 'reports'") if not cur.fetchall(): cur.execute('CREATE TABLE reports (json text)') elif sys.argv[1] == 'dump':
import people as __people_module import groups as __groups_module import accommodations as __accommodations_module import charges as __charges_module import years as __years_module import utils from dj_database_url import config as get_db_config raw_db_config = get_db_config(env="OPENSHIFT_STONERETREAT_DB_URL", default="postgres://nwgh@localhost/stoneretreat") submodules = { "people": __people_module, "groups": __groups_module, "accommodations": __accommodations_module, "charges": __charges_module, "years": __years_module, } class ModuleProxy(dict): """Class that wraps our sub-modules to automagically provide a cursor to them when their public functions are called. """
import psycopg2 import sys from dj_database_url import config as get_db_config # Parse the database configuration into something psycopg2 can handle raw_dbconfig = get_db_config(default="postgres://hurley@localhost/srpush") dbconfig = {} if raw_dbconfig["NAME"]: dbconfig["database"] = raw_dbconfig["NAME"] if raw_dbconfig["USER"]: dbconfig["user"] = raw_dbconfig["USER"] if raw_dbconfig["PASSWORD"]: dbconfig["password"] = raw_dbconfig["PASSWORD"] if raw_dbconfig["HOST"]: dbconfig["host"] = raw_dbconfig["HOST"] if raw_dbconfig["PORT"]: dbconfig["port"] = raw_dbconfig["PORT"] def get_conn(): return psycopg2.connect(**dbconfig) if __name__ == "__main__": conn = get_conn() cur = conn.cursor() if sys.argv[1] == "create": cur.execute( """SELECT * from pg_catalog.pg_tables WHERE tablename = 'pushes'"""