Refactor stock-income to use DB context manager. Replaced Pandas with cursor.

This commit is contained in:
Adam 2024-07-03 14:25:20 +02:00
parent d308da4dce
commit 168c1b53cf

View File

@ -749,10 +749,15 @@ async def stock_income(data: TickerData):
symbol = ?
"""
try:
df = pd.read_sql_query(query_template,con, params=(ticker,))
income_statement = ujson.loads(df['income'].iloc[0])
income_statement_growth = ujson.loads(df['income_growth'].iloc[0])
res = clean_financial_data(income_statement,income_statement_growth)
with db_connection(STOCK_DB) as cursor:
cursor.execute(query_template, (ticker,))
result = cursor.fetchone()
if result:
income_statement = ujson.loads(result[0])
income_statement_growth = ujson.loads(result[1])
res = clean_financial_data(income_statement, income_statement_growth)
else:
res = []
except:
res = []