Added web dashboard.

This commit is contained in:
2025-07-21 20:13:18 +02:00
parent e6a853ed38
commit b82ba39aab
9 changed files with 321 additions and 60 deletions

54
rstat_tool/dashboard.py Normal file
View File

@@ -0,0 +1,54 @@
# rstat_tool/dashboard.py
from flask import Flask, render_template
from .database import (
get_overall_summary,
get_subreddit_summary,
get_all_scanned_subreddits
)
app = Flask(__name__, template_folder='../templates')
@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:
return "N/A"
if mc >= 1e12:
return f"${mc/1e12:.2f}T"
elif mc >= 1e9:
return f"${mc/1e9:.2f}B"
elif mc >= 1e6:
return f"${mc/1e6:.2f}M"
else:
return f"${mc:,}"
@app.context_processor
def inject_subreddits():
"""Makes the list of all scanned subreddits available to every template."""
subreddits = get_all_scanned_subreddits()
return dict(subreddits=subreddits)
@app.route("/")
def index():
"""The handler for the main dashboard page."""
# --- CHANGE HERE: Limit the data to the top 10 ---
tickers = get_overall_summary(limit=10)
return render_template("index.html", tickers=tickers)
@app.route("/subreddit/<name>")
def subreddit_dashboard(name):
"""A dynamic route for per-subreddit dashboards."""
# --- CHANGE HERE: Limit the data to the top 10 ---
tickers = get_subreddit_summary(name, limit=10)
return render_template("subreddit.html", tickers=tickers, subreddit_name=name)
def start_dashboard():
"""The main function called by the 'rstat-dashboard' command."""
print("Starting Flask server...")
print("Open http://127.0.0.1:5000 in your browser.")
print("Press CTRL+C to stop the server.")
app.run(debug=True)
if __name__ == "__main__":
start_dashboard()