Improve function to update top tickers.
This commit is contained in:
@@ -419,4 +419,34 @@ def get_top_weekly_ticker_symbols():
|
||||
"""
|
||||
results = conn.execute(query, (seven_days_ago_timestamp,)).fetchall()
|
||||
conn.close()
|
||||
return [row['symbol'] for row in results] # Return a simple list of strings
|
||||
return [row['symbol'] for row in results] # Return a simple list of strings
|
||||
|
||||
def get_top_daily_ticker_symbols_for_subreddit(subreddit_name):
|
||||
"""Gets a list of the Top 10 daily ticker symbols for a specific subreddit."""
|
||||
conn = get_db_connection()
|
||||
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
one_day_ago_timestamp = int(one_day_ago.timestamp())
|
||||
query = """
|
||||
SELECT t.symbol FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||
JOIN subreddits s ON m.subreddit_id = s.id
|
||||
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp >= ?
|
||||
GROUP BY t.symbol ORDER BY COUNT(m.id) DESC LIMIT 10;
|
||||
"""
|
||||
results = conn.execute(query, (subreddit_name, one_day_ago_timestamp,)).fetchall()
|
||||
conn.close()
|
||||
return [row['symbol'] for row in results]
|
||||
|
||||
def get_top_weekly_ticker_symbols_for_subreddit(subreddit_name):
|
||||
"""Gets a list of the Top 10 weekly ticker symbols for a specific subreddit."""
|
||||
conn = get_db_connection()
|
||||
seven_days_ago = datetime.now(timezone.utc) - timedelta(days=7)
|
||||
seven_days_ago_timestamp = int(seven_days_ago.timestamp())
|
||||
query = """
|
||||
SELECT t.symbol FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||
JOIN subreddits s ON m.subreddit_id = s.id
|
||||
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp >= ?
|
||||
GROUP BY t.symbol ORDER BY COUNT(m.id) DESC LIMIT 10;
|
||||
"""
|
||||
results = conn.execute(query, (subreddit_name, seven_days_ago_timestamp,)).fetchall()
|
||||
conn.close()
|
||||
return [row['symbol'] for row in results]
|
Reference in New Issue
Block a user