From d59e67b55d1fe4d0c80e99c56773eda52858bb65 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 6 Feb 2026 18:17:33 +0000 Subject: [PATCH] Display total count of photos obtained via Flickr mail Show the total number of successful Flickr mail requests on the home page, not just the count of recent uploads displayed. Co-Authored-By: Claude Opus 4.5 --- main.py | 38 ++++++++++++++++++++++++-------------- templates/combined.html | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 5d223cf..d2cc090 100755 --- a/main.py +++ b/main.py @@ -323,33 +323,39 @@ def fetch_commons_thumbnails(titles: list[str]) -> dict[str, str]: return thumbnails -def get_recent_commons_uploads() -> list[CommonsUpload]: - """Get recent Commons uploads with thumbnails, filtered to those contacted via Flickr mail.""" +def get_recent_commons_uploads() -> tuple[list[CommonsUpload], int]: + """Get recent Commons uploads with thumbnails, filtered to those contacted via Flickr mail. + + Returns a tuple of (uploads_list, total_count) where total_count is the total number + of uploads obtained via Flickr mail (not just the ones returned). + """ if not COMMONS_UPLOADS_FILE.exists(): - return [] + return [], 0 try: with open(COMMONS_UPLOADS_FILE) as f: all_uploads = json.load(f) except (json.JSONDecodeError, OSError): - return [] + return [], 0 # Build sent mail index sent_mail_index = build_sent_mail_index() # Filter uploads to only those with matching sent mail + # Count all matches, but only keep RECENT_UPLOADS_COUNT for display uploads_with_mail: list[dict[str, typing.Any]] = [] + total_matched = 0 for upload in all_uploads: flickr_url = upload.get("flickr_url", "") normalized = normalize_flickr_url(flickr_url) if normalized and normalized in sent_mail_index: - upload["_mail_info"] = sent_mail_index[normalized] - uploads_with_mail.append(upload) - if len(uploads_with_mail) >= RECENT_UPLOADS_COUNT: - break + total_matched += 1 + if len(uploads_with_mail) < RECENT_UPLOADS_COUNT: + upload["_mail_info"] = sent_mail_index[normalized] + uploads_with_mail.append(upload) if not uploads_with_mail: - return [] + return [], 0 # Load cache and check if it's still valid cache = load_commons_thumbnail_cache() @@ -395,7 +401,7 @@ def get_recent_commons_uploads() -> list[CommonsUpload]: ) ) - return result + return result, total_matched def is_valid_flickr_image_url(url: str) -> bool: @@ -574,12 +580,16 @@ def start() -> str: """Start form.""" enwp = flask.request.args.get("enwp") if not enwp: - recent_uploads = get_recent_commons_uploads() - return flask.render_template("combined.html", recent_uploads=recent_uploads) + recent_uploads, total_uploads = get_recent_commons_uploads() + return flask.render_template( + "combined.html", recent_uploads=recent_uploads, total_uploads=total_uploads + ) enwp = enwp.strip() if not enwp: - recent_uploads = get_recent_commons_uploads() - return flask.render_template("combined.html", recent_uploads=recent_uploads) + recent_uploads, total_uploads = get_recent_commons_uploads() + return flask.render_template( + "combined.html", recent_uploads=recent_uploads, total_uploads=total_uploads + ) input_is = "url" if enwiki in enwp else "title" diff --git a/templates/combined.html b/templates/combined.html index c7f026a..522dfaf 100644 --- a/templates/combined.html +++ b/templates/combined.html @@ -18,7 +18,7 @@ {% if recent_uploads is defined and recent_uploads and not name %}
Recent uploads to Wikimedia Commons
-

Photos obtained via Flickr mail requests

+

{{ total_uploads }} photos obtained via Flickr mail requests

{% for upload in recent_uploads %}