Format all code.

This commit is contained in:
2025-07-25 23:22:37 +02:00
parent f940470de3
commit 56e0965a5f
19 changed files with 850 additions and 353 deletions

View File

@@ -8,13 +8,14 @@ from .database import (
get_deep_dive_details,
get_daily_summary_for_subreddit,
get_weekly_summary_for_subreddit,
get_overall_daily_summary, # Now correctly imported
get_overall_weekly_summary # Now correctly imported
get_overall_daily_summary, # Now correctly imported
get_overall_weekly_summary, # Now correctly imported
)
app = Flask(__name__, template_folder='../templates')
app = Flask(__name__, template_folder="../templates")
@app.template_filter('format_mc')
@app.template_filter("format_mc")
def format_market_cap(mc):
"""Formats a large number into a readable market cap string."""
if mc is None or mc == 0:
@@ -28,26 +29,28 @@ def format_market_cap(mc):
else:
return f"${mc:,}"
@app.context_processor
def inject_subreddits():
"""Makes the list of all subreddits available to every template for the navbar."""
return dict(all_subreddits=get_all_scanned_subreddits())
@app.route("/")
def overall_dashboard():
"""Handler for the main, overall dashboard."""
view_type = request.args.get('view', 'daily')
is_image_mode = request.args.get('image') == 'true'
if view_type == 'weekly':
view_type = request.args.get("view", "daily")
is_image_mode = request.args.get("image") == "true"
if view_type == "weekly":
tickers, start, end = get_overall_weekly_summary()
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
subtitle = "All Subreddits - Top 10 Weekly"
else: # Default to daily
else: # Default to daily
tickers = get_overall_daily_summary()
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
subtitle = "All Subreddits - Top 10 Daily"
return render_template(
"dashboard_view.html",
title="Overall Dashboard",
@@ -57,26 +60,27 @@ def overall_dashboard():
view_type=view_type,
subreddit_name=None,
is_image_mode=is_image_mode,
base_url="/"
base_url="/",
)
@app.route("/subreddit/<name>")
def subreddit_dashboard(name):
"""Handler for per-subreddit dashboards."""
view_type = request.args.get('view', 'daily')
is_image_mode = request.args.get('image') == 'true'
if view_type == 'weekly':
view_type = request.args.get("view", "daily")
is_image_mode = request.args.get("image") == "true"
if view_type == "weekly":
today = datetime.now(timezone.utc)
target_date = today - timedelta(days=7)
tickers, start, end = get_weekly_summary_for_subreddit(name, target_date)
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
subtitle = f"r/{name} - Top 10 Weekly"
else: # Default to daily
else: # Default to daily
tickers = get_daily_summary_for_subreddit(name)
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
subtitle = f"r/{name} - Top 10 Daily"
return render_template(
"dashboard_view.html",
title=f"r/{name} Dashboard",
@@ -86,9 +90,10 @@ def subreddit_dashboard(name):
view_type=view_type,
subreddit_name=name,
is_image_mode=is_image_mode,
base_url=f"/subreddit/{name}"
base_url=f"/subreddit/{name}",
)
@app.route("/deep-dive/<symbol>")
def deep_dive(symbol):
"""The handler for the deep-dive page for a specific ticker."""
@@ -96,6 +101,7 @@ def deep_dive(symbol):
posts = get_deep_dive_details(symbol)
return render_template("deep_dive.html", posts=posts, symbol=symbol)
def start_dashboard():
"""The main function called by the 'rstat-dashboard' command."""
log.info("Starting Flask server...")
@@ -103,5 +109,6 @@ def start_dashboard():
log.info("Press CTRL+C to stop the server.")
app.run(debug=True)
if __name__ == "__main__":
start_dashboard()
start_dashboard()