def setUp(self): db_host = os.environ.get('DB_HOST') db_url = 'postgresql://{user}:{passwd}@{db_host}/{db}'.format( user='******', passwd='tester', db_host=db_host, db='idetect_test') engine = create_engine(db_url) Session.configure(bind=engine) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) self.session = Session()
def setUp(self): logger.debug("setUp") worker_logger = logging.getLogger("idetect.worker") worker_logger.setLevel(logging.INFO) logger.debug("Connecting to DB") db_host = os.environ.get('DB_HOST') db_port = os.environ.get('DB_PORT', 5432) db_user = os.environ.get('DB_USER', 'tester') db_pass = os.environ.get('DB_PASSWORD', 'tester') db_url = 'postgresql://{user}:{passwd}@{db_host}:{db_port}/{db}'.format( user=db_user, passwd=db_pass, db_host=db_host, db_port=db_port, db='idetect') self.engine = create_engine(db_url, echo=False) Session.configure(bind=self.engine) self.session = Session() self.session.query(FactApi).count() logger.debug("setUp complete")
from sqlalchemy import create_engine from idetect.model import db_url, Base, Session, Country, FactKeyword from idetect.load_data import load_countries, load_terms import re import string import numpy as np import pandas as pd from idetect.nlp_models.category import * from idetect.nlp_models.relevance import * from idetect.nlp_models.base_model import CustomSklLsiModel if __name__ == "__main__": # Create the Database engine = create_engine(db_url()) Session.configure(bind=engine) Base.metadata.create_all(engine) session = Session() # Load the Countries data if necessary countries = session.query(Country).all() if len(countries) == 0: load_countries(session) # Load the Keywords if neccessary keywords = session.query(FactKeyword).all() if len(keywords) == 0: load_terms(session) session.close()