Big improvements on image view.

This commit is contained in:
2025-07-22 20:53:38 +02:00
parent 45818046a2
commit 2688a7df44
9 changed files with 324 additions and 326 deletions

View File

@@ -1,6 +1,6 @@
# rstat_tool/dashboard.py
from flask import Flask, render_template
from flask import Flask, render_template, request
from datetime import datetime, timedelta, timezone
from .logger_setup import get_logger
from .database import (
@@ -69,13 +69,30 @@ def daily_image_view(name):
@app.route("/image/weekly/<name>")
def weekly_image_view(name):
"""The handler for the WEEKLY image-style dashboard."""
tickers = get_weekly_summary_for_subreddit(name)
# Create the date range string for the title
end_date = datetime.now(timezone.utc)
start_date = end_date - timedelta(days=7)
date_range_str = f"{start_date.strftime('%b %d')} - {end_date.strftime('%b %d, %Y')}"
"""
The handler for the WEEKLY image-style dashboard.
Accepts an optional 'date' query parameter in YYYY-MM-DD format.
"""
# Get the date from the URL query string, e.g., ?date=2025-07-21
date_str = request.args.get('date')
target_date = None
if date_str:
try:
# Convert the string to a datetime object
target_date = datetime.strptime(date_str, "%Y-%m-%d").replace(tzinfo=timezone.utc)
except ValueError:
return "Invalid date format. Please use YYYY-MM-DD.", 400
else:
# If no date is provided, default to showing LAST week
today = datetime.now(timezone.utc)
target_date = today - timedelta(days=7)
# The query now returns the results and the date objects used
tickers, start_of_week, end_of_week = get_weekly_summary_for_subreddit(name, target_date)
# Format the date range for the title
date_range_str = f"{start_of_week.strftime('%b %d')} - {end_of_week.strftime('%b %d, %Y')}"
return render_template(
"weekly_image_view.html",