bugfixing watchlist
This commit is contained in:
parent
0bf40a7661
commit
914cc93712
64
app/main.py
64
app/main.py
@ -1027,31 +1027,6 @@ async def get_watchlist(data: GetWatchList, api_key: str = Security(get_api_key)
|
|||||||
result = pb.collection("watchlist").get_one(watchlist_id)
|
result = pb.collection("watchlist").get_one(watchlist_id)
|
||||||
ticker_list = result.ticker
|
ticker_list = result.ticker
|
||||||
|
|
||||||
query_stocks = """
|
|
||||||
SELECT
|
|
||||||
stock_news
|
|
||||||
FROM
|
|
||||||
stocks
|
|
||||||
WHERE
|
|
||||||
symbol = ?
|
|
||||||
"""
|
|
||||||
query_etf = """
|
|
||||||
SELECT
|
|
||||||
etf_news
|
|
||||||
FROM
|
|
||||||
etfs
|
|
||||||
WHERE
|
|
||||||
symbol = ?
|
|
||||||
"""
|
|
||||||
|
|
||||||
query_crypto = """
|
|
||||||
SELECT
|
|
||||||
crypto_news
|
|
||||||
FROM
|
|
||||||
cryptos
|
|
||||||
WHERE
|
|
||||||
symbol = ?
|
|
||||||
"""
|
|
||||||
|
|
||||||
combined_results = [] # List to store the combined results
|
combined_results = [] # List to store the combined results
|
||||||
combined_news = []
|
combined_news = []
|
||||||
@ -1066,13 +1041,12 @@ async def get_watchlist(data: GetWatchList, api_key: str = Security(get_api_key)
|
|||||||
combined_results.append(quote_dict)
|
combined_results.append(quote_dict)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
df = pd.read_sql_query(query_etf, etf_con, params=(ticker,))
|
try:
|
||||||
if not df.empty:
|
with open(f"json/market-news/companies/{ticker}.json", 'rb') as file:
|
||||||
df_dict = df.to_dict()
|
news_dict = orjson.loads(file.read())[0]
|
||||||
try:
|
combined_news.append(news_dict)
|
||||||
combined_news.append(orjson.loads(df_dict['etf_news'][0])[0])
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
|
||||||
elif ticker in crypto_symbols:
|
elif ticker in crypto_symbols:
|
||||||
try:
|
try:
|
||||||
with open(f"json/quote/{ticker}.json", 'rb') as file:
|
with open(f"json/quote/{ticker}.json", 'rb') as file:
|
||||||
@ -1081,13 +1055,12 @@ async def get_watchlist(data: GetWatchList, api_key: str = Security(get_api_key)
|
|||||||
combined_results.append(quote_dict)
|
combined_results.append(quote_dict)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
df = pd.read_sql_query(query_crypto, crypto_con, params=(ticker,))
|
try:
|
||||||
if not df.empty:
|
with open(f"json/market-news/companies/{ticker}.json", 'rb') as file:
|
||||||
df_dict = df.to_dict()
|
news_dict = orjson.loads(file.read())[0]
|
||||||
try:
|
combined_news.append(news_dict)
|
||||||
combined_news.append(orjson.loads(df_dict['crypto_news'][0])[0])
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with open(f"json/quote/{ticker}.json", 'rb') as file:
|
with open(f"json/quote/{ticker}.json", 'rb') as file:
|
||||||
@ -1096,13 +1069,12 @@ async def get_watchlist(data: GetWatchList, api_key: str = Security(get_api_key)
|
|||||||
combined_results.append(quote_dict)
|
combined_results.append(quote_dict)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
df = pd.read_sql_query(query_stocks, con, params=(ticker,))
|
try:
|
||||||
if not df.empty:
|
with open(f"json/market-news/companies/{ticker}.json", 'rb') as file:
|
||||||
df_dict = df.to_dict()
|
news_dict = orjson.loads(file.read())[0]
|
||||||
try:
|
combined_news.append(news_dict)
|
||||||
combined_news.append(orjson.loads(df_dict['stock_news'][0])[0])
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
|
||||||
res = [combined_results, combined_news]
|
res = [combined_results, combined_news]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user