From 6e0c35326eb82931e188678d25657b82089b9c46 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 12 Nov 2024 11:51:47 +0100 Subject: [PATCH] update cron list --- app/cron_list.py | 63 +++++++++++++++++++++++++++++- app/main.py | 2 - app/restart_json.py | 95 ++++----------------------------------------- 3 files changed, 68 insertions(+), 92 deletions(-) diff --git a/app/cron_list.py b/app/cron_list.py index e7105bb..b49aabc 100644 --- a/app/cron_list.py +++ b/app/cron_list.py @@ -203,10 +203,69 @@ async def get_magnificent_seven(): with open(f"json/magnificent-seven/data.json", 'wb') as file: file.write(orjson.dumps(res_list)) - print(res_list) + + +async def etf_bitcoin_list(): + try: + with sqlite3.connect('etf.db') as etf_con: + etf_cursor = etf_con.cursor() + etf_cursor.execute("PRAGMA journal_mode = wal") + etf_cursor.execute("SELECT DISTINCT symbol FROM etfs") + etf_symbols = [row[0] for row in etf_cursor.fetchall()] + + result_list = [] + query_template = """ + SELECT + symbol, name, expenseRatio, totalAssets + FROM + etfs + WHERE + symbol = ? + """ + + for symbol in etf_symbols: + try: + data = pd.read_sql_query(query_template, etf_con, params=(symbol,)) + name = data['name'].iloc[0] + + if 'bitcoin' in name.lower(): + expense_ratio = round(float(data['expenseRatio'].iloc[0]), 2) + total_assets = int(data['totalAssets'].iloc[0]) + + try: + with open(f"json/quote/{symbol}.json", "rb") as file: + quote_data = orjson.loads(file.read()) + except (FileNotFoundError, orjson.JSONDecodeError): + quote_data = None + + price = round(quote_data.get('price'), 2) if quote_data else None + changesPercentage = round(quote_data.get('changesPercentage'), 2) if quote_data else None + if total_assets > 0: + result_list.append({ + 'symbol': symbol, + 'name': name, + 'expenseRatio': expense_ratio, + 'totalAssets': total_assets, + 'price': price, + 'changesPercentage': changesPercentage + }) + except Exception as e: + print(f"Error processing symbol {symbol}: {e}") + + if result_list: + result_list = sorted(result_list, key=lambda x: x['totalAssets'], reverse=True) + for rank, item in enumerate(result_list, start=1): + item['rank'] = rank + + with open("json/etf-bitcoin-list/data.json", 'wb') as file: + file.write(orjson.dumps(result_list)) + + except Exception as e: + print(f"Database error: {e}") + async def run(): - + await etf_bitcoin_list() await get_magnificent_seven() """Main function to run the analysis for all categories""" diff --git a/app/main.py b/app/main.py index f275b02..9481522 100755 --- a/app/main.py +++ b/app/main.py @@ -1861,8 +1861,6 @@ async def etf_holdings(data: TickerData, api_key: str = Security(get_api_key)): - - @app.post("/exchange-constituents") async def top_ai_signals(data:FilterStockList, api_key: str = Security(get_api_key)): data = data.dict() diff --git a/app/restart_json.py b/app/restart_json.py index 5c2bab2..7ad476c 100755 --- a/app/restart_json.py +++ b/app/restart_json.py @@ -1519,11 +1519,17 @@ async def get_congress_rss_feed(symbols, etf_symbols, crypto_symbols): for item in data: ticker = item.get("ticker") ticker = ticker.replace('BRK.A','BRK-A') + ticker = ticker.replace('BRK/A','BRK-A') ticker = ticker.replace('BRK.B','BRK-B') + ticker = ticker.replace('BRK/B','BRK-B') if item['assetDescription'] == 'Bitcoin': item['ticker'] = 'BTCUSD' ticker = item.get("ticker") + + if item['assetDescription'] == 'Ethereum': + item['ticker'] = 'ETHUSD' + ticker = item.get("ticker") item['assetDescription'] = item['assetDescription'].replace('U.S','US') @@ -1732,48 +1738,6 @@ async def get_all_crypto_tickers(crypto_con): return crypto_list_data -async def get_magnificent_seven(con): - - symbol_list = ['MSFT','AAPL','GOOGL','AMZN','NVDA','META','TSLA'] - - query_template = """ - SELECT - symbol, name, price, changesPercentage, marketCap,pe - FROM - stocks - WHERE - symbol = ? - """ - - res_list = [] - for symbol in symbol_list: - try: - try: - with open(f"json/financial-statements/income-statement/annual/{symbol}.json", 'rb') as file: - json_data = orjson.loads(file.read())[0] - revenue = json_data['revenue'] - netIncome = json_data['netIncome'] - except: - revenue = None - netIncome = None - - data = pd.read_sql_query(query_template, con, params=(symbol,)) - - name = data['name'].iloc[0] - - price = round(float(data['price'].iloc[0]),2) - changesPercentage = round(float(data['changesPercentage'].iloc[0]),2) - marketCap = int(data['marketCap'].iloc[0]) - pe = round(float(data['pe'].iloc[0]),2) - - res_list.append({'symbol': symbol, 'name': name, 'price': price, \ - 'changesPercentage': changesPercentage, 'marketCap': marketCap, \ - 'revenue': revenue, 'netIncome': netIncome, 'pe': pe}) - - except Exception as e: - print(e) - - return res_list async def etf_providers(etf_con, etf_symbols): @@ -1834,46 +1798,6 @@ async def etf_providers(etf_con, etf_symbols): return result_list -async def etf_bitcoin_list(etf_con, etf_symbols): - - - result_list = [] - - query_template = """ - SELECT - symbol, name, expenseRatio, totalAssets - FROM - etfs - WHERE - symbol = ? - """ - - for symbol in etf_symbols: - try: - data = pd.read_sql_query(query_template, etf_con, params=(symbol,)) - name = data['name'].iloc[0] - if ('Bitcoin' or 'bitcoin') in name: - expense_ratio = round(float(data['expenseRatio'].iloc[0]),2) - total_assets = int(data['totalAssets'].iloc[0]) - - result_list.append( - {'symbol': symbol, - 'name': name, - 'expenseRatio': expense_ratio, - 'totalAssets': total_assets - } - ) - else: - pass - - except Exception as e: - print(e) - - result_list = sorted(result_list, key=lambda x: x['totalAssets'], reverse=True) - - return result_list - - async def get_ipo_calendar(con, symbols): # Define function to get end date of each quarter @@ -2096,9 +2020,7 @@ async def save_json_files(): ujson.dump(data, file) - data = await etf_bitcoin_list(etf_con, etf_symbols) - with open(f"json/etf-bitcoin-list/data.json", 'w') as file: - ujson.dump(data, file) + data = await etf_providers(etf_con, etf_symbols) with open(f"json/all-etf-providers/data.json", 'w') as file: @@ -2127,9 +2049,6 @@ async def save_json_files(): with open(f"json/stocks-list/sp500_constituent.json", 'w') as file: ujson.dump(data, file) - data = await get_magnificent_seven(con) - with open(f"json/magnificent-seven/data.json", 'w') as file: - ujson.dump(data, file) con.close()