diff --git a/app.py b/app.py index 833d84a..20a423e 100644 --- a/app.py +++ b/app.py @@ -271,9 +271,32 @@ def check_first_user(): pass +def calculate_quick_stats(): + """Calculate quick stats for dashboard""" + from datetime import datetime, timedelta + + cached_posts, _ = _load_posts_cache() + + # Calculate posts from today (last 24 hours) + now = datetime.utcnow() + today_start = now - timedelta(hours=24) + today_timestamp = today_start.timestamp() + + posts_today = sum(1 for post in cached_posts.values() + if post.get('timestamp', 0) >= today_timestamp) + + return { + 'posts_today': posts_today, + 'total_posts': len(cached_posts) + } + + @app.route('/') def index(): """Serve the main feed page""" + # Calculate stats + quick_stats = calculate_quick_stats() + if current_user.is_authenticated: # Load user settings try: @@ -282,7 +305,7 @@ def index(): logger.warning(f"Invalid user settings JSON for user {current_user.id}: {e}") user_settings = {} - return render_template('dashboard.html', user_settings=user_settings) + return render_template('dashboard.html', user_settings=user_settings, quick_stats=quick_stats) else: # Check if anonymous access is allowed if app.config.get('ALLOW_ANONYMOUS_ACCESS', False): @@ -297,7 +320,7 @@ def index(): 'dark_patterns_opt_in': False } } - return render_template('dashboard.html', user_settings=user_settings, anonymous=True) + return render_template('dashboard.html', user_settings=user_settings, anonymous=True, quick_stats=quick_stats) else: # Redirect non-authenticated users to login return redirect(url_for('login')) diff --git a/templates/dashboard.html b/templates/dashboard.html index 10cda5c..32fb28e 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -84,7 +84,7 @@

Quick Stats

-
156
+
{{ quick_stats.posts_today if quick_stats else 0 }}
Posts Today