update cron list

This commit is contained in:
MuslemRahimi 2024-11-12 11:51:47 +01:00
parent 09751c8481
commit 6e0c35326e
3 changed files with 68 additions and 92 deletions

View File

@ -203,10 +203,69 @@ async def get_magnificent_seven():
with open(f"json/magnificent-seven/data.json", 'wb') as file: with open(f"json/magnificent-seven/data.json", 'wb') as file:
file.write(orjson.dumps(res_list)) 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(): async def run():
await etf_bitcoin_list()
await get_magnificent_seven() await get_magnificent_seven()
"""Main function to run the analysis for all categories""" """Main function to run the analysis for all categories"""

View File

@ -1861,8 +1861,6 @@ async def etf_holdings(data: TickerData, api_key: str = Security(get_api_key)):
@app.post("/exchange-constituents") @app.post("/exchange-constituents")
async def top_ai_signals(data:FilterStockList, api_key: str = Security(get_api_key)): async def top_ai_signals(data:FilterStockList, api_key: str = Security(get_api_key)):
data = data.dict() data = data.dict()

View File

@ -1519,12 +1519,18 @@ async def get_congress_rss_feed(symbols, etf_symbols, crypto_symbols):
for item in data: for item in data:
ticker = item.get("ticker") ticker = item.get("ticker")
ticker = ticker.replace('BRK.A','BRK-A') 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')
ticker = ticker.replace('BRK/B','BRK-B')
if item['assetDescription'] == 'Bitcoin': if item['assetDescription'] == 'Bitcoin':
item['ticker'] = 'BTCUSD' item['ticker'] = 'BTCUSD'
ticker = item.get("ticker") ticker = item.get("ticker")
if item['assetDescription'] == 'Ethereum':
item['ticker'] = 'ETHUSD'
ticker = item.get("ticker")
item['assetDescription'] = item['assetDescription'].replace('U.S','US') item['assetDescription'] = item['assetDescription'].replace('U.S','US')
@ -1732,48 +1738,6 @@ async def get_all_crypto_tickers(crypto_con):
return crypto_list_data 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): async def etf_providers(etf_con, etf_symbols):
@ -1834,46 +1798,6 @@ async def etf_providers(etf_con, etf_symbols):
return result_list 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): async def get_ipo_calendar(con, symbols):
# Define function to get end date of each quarter # Define function to get end date of each quarter
@ -2096,9 +2020,7 @@ async def save_json_files():
ujson.dump(data, file) 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) data = await etf_providers(etf_con, etf_symbols)
with open(f"json/all-etf-providers/data.json", 'w') as file: 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: with open(f"json/stocks-list/sp500_constituent.json", 'w') as file:
ujson.dump(data, 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() con.close()