diff --git a/binance_db/db.py b/binance_db/db.py index c4748ba..b4f0fd5 100644 --- a/binance_db/db.py +++ b/binance_db/db.py @@ -3,8 +3,11 @@ from sqlalchemy.orm import sessionmaker class BinanceDB(): - def __init__(self, connstr, echo=False): - self.engine = create_engine(connstr, echo=echo) + def __init__(self, password, user='binancedb', url='postgres', port=5432, db='binancedb', echo=False): + conn = 'postgresql://{}:{}@{}:{}/{}'.format( + user, password, url, port, db) + + self.engine = create_engine(conn, echo=echo) Candle.metadata.create_all(self.engine) def get_session(self): diff --git a/main.py b/main.py index 83f5fff..e333f82 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,7 @@ def connect_db(): pgport = os.environ['BDB_POSTGRES_PORT'] pguser = os.environ['BDB_POSTGRES_USER'] pgpass = os.environ['BDB_POSTGRES_PASS'] - conn = f'postgresql://{pguser}:{pgpass}@{pgurl}:{pgport}/{pguser}' + pgdb = os.environ['BDB_POSTGRES_DB'] # let pg start up. first run can take longer than others logger.info("Waiting for Postgres...") @@ -39,7 +39,7 @@ def connect_db(): while True: time.sleep(5) try: - bdb = BinanceDB(conn) + bdb = BinanceDB(user=pguser, password=pgpass, url=pgurl, port=pgport, db=pgdb) break except: pg_try += 1