Added option to add top parameter to view e.g. top 20 or top 50.
This commit is contained in:
@@ -238,7 +238,7 @@ def get_week_start_end(for_date):
|
||||
return start_of_week, end_of_week
|
||||
|
||||
|
||||
def get_overall_daily_summary():
|
||||
def get_overall_daily_summary(limit=10):
|
||||
"""Gets the top tickers across all subreddits from the LAST 24 HOURS."""
|
||||
conn = get_db_connection()
|
||||
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
@@ -250,14 +250,14 @@ def get_overall_daily_summary():
|
||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||
WHERE m.mention_timestamp >= ?
|
||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||
ORDER BY total_mentions DESC LIMIT 10;
|
||||
ORDER BY total_mentions DESC LIMIT ?;
|
||||
"""
|
||||
results = conn.execute(query, (one_day_ago_timestamp,)).fetchall()
|
||||
results = conn.execute(query, (one_day_ago_timestamp, limit)).fetchall()
|
||||
conn.close()
|
||||
return results
|
||||
|
||||
|
||||
def get_overall_weekly_summary():
|
||||
def get_overall_weekly_summary(limit=10):
|
||||
"""Gets the top tickers across all subreddits for LAST WEEK (Mon-Sun)."""
|
||||
conn = get_db_connection()
|
||||
today = datetime.now(timezone.utc)
|
||||
@@ -272,14 +272,14 @@ def get_overall_weekly_summary():
|
||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||
WHERE m.mention_timestamp BETWEEN ? AND ?
|
||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||
ORDER BY total_mentions DESC LIMIT 10;
|
||||
ORDER BY total_mentions DESC LIMIT ?;
|
||||
"""
|
||||
results = conn.execute(query, (start_timestamp, end_timestamp)).fetchall()
|
||||
results = conn.execute(query, (start_timestamp, end_timestamp, limit)).fetchall()
|
||||
conn.close()
|
||||
return results, start_of_week, end_of_week
|
||||
|
||||
|
||||
def get_daily_summary_for_subreddit(subreddit_name):
|
||||
def get_daily_summary_for_subreddit(subreddit_name, limit=10):
|
||||
"""Gets a summary for a subreddit's DAILY view (last 24 hours)."""
|
||||
conn = get_db_connection()
|
||||
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
@@ -291,14 +291,14 @@ def get_daily_summary_for_subreddit(subreddit_name):
|
||||
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, t.market_cap, t.closing_price
|
||||
ORDER BY total_mentions DESC LIMIT 10;
|
||||
ORDER BY total_mentions DESC LIMIT ?;
|
||||
"""
|
||||
results = conn.execute(query, (subreddit_name, one_day_ago_timestamp)).fetchall()
|
||||
results = conn.execute(query, (subreddit_name, one_day_ago_timestamp, limit)).fetchall()
|
||||
conn.close()
|
||||
return results
|
||||
|
||||
|
||||
def get_weekly_summary_for_subreddit(subreddit_name, for_date):
|
||||
def get_weekly_summary_for_subreddit(subreddit_name, for_date, limit=10):
|
||||
"""Gets a summary for a subreddit's WEEKLY view (for a specific week)."""
|
||||
conn = get_db_connection()
|
||||
start_of_week, end_of_week = get_week_start_end(for_date)
|
||||
@@ -311,10 +311,10 @@ def get_weekly_summary_for_subreddit(subreddit_name, for_date):
|
||||
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 BETWEEN ? AND ?
|
||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||
ORDER BY total_mentions DESC LIMIT 10;
|
||||
ORDER BY total_mentions DESC LIMIT ?;
|
||||
"""
|
||||
results = conn.execute(
|
||||
query, (subreddit_name, start_timestamp, end_timestamp)
|
||||
query, (subreddit_name, start_timestamp, end_timestamp, limit)
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return results, start_of_week, end_of_week
|
||||
|
Reference in New Issue
Block a user