def test_Whether_DB_Is_Connecting_And_Returning_Values(self): conn = PostgresConnection() conn.init_from_file('simple.json', 'dev', 'dbConfig') conn.open_connection() query = Query('public."application"').select().column('*').from_table() db = Postgres(conn) rows = db.fetch_all(query.query_built) print(rows) print(len(rows)) self.assertTrue(len(rows) > 0) conn.close_connection()
def stockmonthrevenue(self): logger.info(__name__) for i in self.pool: sid = i[0] logger.info('get {} stock month revenue'.format(sid)) Postgres.run("delete from stock_mom_revenue where stock_id = '{}' and date >= '{}';".format(sid, self.date)) payload = {'dataset': 'TaiwanStockMonthRevenue', 'stock_id': sid, 'date': self.date} res = requests.get(self.url, params=payload) temp = res.json() data = pd.DataFrame(temp['data']) data.to_sql(name='stock_mom_revenue', con=self.engine, if_exists='append', index=False) time.sleep(10)
def get(self, account): db = Postgres.Connection() result = db.get_password(account=account) return Reply.password(result), 200
def __init__(self): self.engine = Config.create_ng() self.url = FinMind.api() self.date = Config.txdate() self.pool = Postgres.get("select distinct stock_id from stock_info where length(stock_id) = 4 and " "industry_category <> 'ETF' order by stock_id asc;")