Improve function to update top tickers.
This commit is contained in:
@@ -200,18 +200,37 @@ def main():
|
||||
database.initialize_db()
|
||||
|
||||
if args.update_top_tickers:
|
||||
# --- Mode 1: Update Top Tickers ---
|
||||
log.critical("--- Starting Financial Data Update for Top Tickers ---")
|
||||
top_daily = database.get_top_daily_ticker_symbols()
|
||||
top_weekly = database.get_top_weekly_ticker_symbols()
|
||||
unique_top_tickers = sorted(list(set(top_daily + top_weekly)))
|
||||
|
||||
# 1. Start with an empty set to hold all unique tickers
|
||||
tickers_to_update = set()
|
||||
|
||||
# 2. Get the overall top tickers
|
||||
log.info("-> Checking overall top daily and weekly tickers...")
|
||||
top_daily_overall = database.get_top_daily_ticker_symbols()
|
||||
top_weekly_overall = database.get_top_weekly_ticker_symbols()
|
||||
tickers_to_update.update(top_daily_overall)
|
||||
tickers_to_update.update(top_weekly_overall)
|
||||
|
||||
# 3. Get all subreddits and loop through them
|
||||
all_subreddits = database.get_all_scanned_subreddits()
|
||||
log.info(f"-> Checking top tickers for {len(all_subreddits)} individual subreddit(s)...")
|
||||
for sub_name in all_subreddits:
|
||||
log.debug(f" -> Checking r/{sub_name}...")
|
||||
top_daily_sub = database.get_top_daily_ticker_symbols_for_subreddit(sub_name)
|
||||
top_weekly_sub = database.get_top_weekly_ticker_symbols_for_subreddit(sub_name)
|
||||
tickers_to_update.update(top_daily_sub)
|
||||
tickers_to_update.update(top_weekly_sub)
|
||||
|
||||
unique_top_tickers = sorted(list(tickers_to_update))
|
||||
|
||||
if not unique_top_tickers:
|
||||
log.info("No top tickers found in the last week. Nothing to update.")
|
||||
else:
|
||||
log.info(f"Found {len(unique_top_tickers)} unique tickers to update: {', '.join(unique_top_tickers)}")
|
||||
log.info(f"Found {len(unique_top_tickers)} unique top tickers to update: {', '.join(unique_top_tickers)}")
|
||||
conn = database.get_db_connection()
|
||||
for ticker_symbol in unique_top_tickers:
|
||||
# 4. Find the ticker's ID to perform the update
|
||||
ticker_info = database.get_ticker_by_symbol(ticker_symbol)
|
||||
if ticker_info:
|
||||
log.info(f" -> Updating financials for {ticker_info['symbol']}...")
|
||||
@@ -222,6 +241,7 @@ def main():
|
||||
financials.get('closing_price')
|
||||
)
|
||||
conn.close()
|
||||
|
||||
log.critical("--- Top Ticker Financial Data Update Complete ---")
|
||||
|
||||
elif args.update_financials_only:
|
||||
|
Reference in New Issue
Block a user