Skip to content

Commit

Permalink
db init params
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-kleiner committed Jun 17, 2018
1 parent dee8cfb commit 510341f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions binance_db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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...")
pg_try = 0
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
Expand Down

0 comments on commit 510341f

Please sign in to comment.