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 <noreply@anthropic.com>
This commit is contained in:
parent
a2d29d7937
commit
d59e67b55d
2 changed files with 25 additions and 15 deletions
34
main.py
34
main.py
|
|
@ -323,33 +323,39 @@ def fetch_commons_thumbnails(titles: list[str]) -> dict[str, str]:
|
||||||
return thumbnails
|
return thumbnails
|
||||||
|
|
||||||
|
|
||||||
def get_recent_commons_uploads() -> list[CommonsUpload]:
|
def get_recent_commons_uploads() -> tuple[list[CommonsUpload], int]:
|
||||||
"""Get recent Commons uploads with thumbnails, filtered to those contacted via Flickr mail."""
|
"""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():
|
if not COMMONS_UPLOADS_FILE.exists():
|
||||||
return []
|
return [], 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(COMMONS_UPLOADS_FILE) as f:
|
with open(COMMONS_UPLOADS_FILE) as f:
|
||||||
all_uploads = json.load(f)
|
all_uploads = json.load(f)
|
||||||
except (json.JSONDecodeError, OSError):
|
except (json.JSONDecodeError, OSError):
|
||||||
return []
|
return [], 0
|
||||||
|
|
||||||
# Build sent mail index
|
# Build sent mail index
|
||||||
sent_mail_index = build_sent_mail_index()
|
sent_mail_index = build_sent_mail_index()
|
||||||
|
|
||||||
# Filter uploads to only those with matching sent mail
|
# 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]] = []
|
uploads_with_mail: list[dict[str, typing.Any]] = []
|
||||||
|
total_matched = 0
|
||||||
for upload in all_uploads:
|
for upload in all_uploads:
|
||||||
flickr_url = upload.get("flickr_url", "")
|
flickr_url = upload.get("flickr_url", "")
|
||||||
normalized = normalize_flickr_url(flickr_url)
|
normalized = normalize_flickr_url(flickr_url)
|
||||||
if normalized and normalized in sent_mail_index:
|
if normalized and normalized in sent_mail_index:
|
||||||
|
total_matched += 1
|
||||||
|
if len(uploads_with_mail) < RECENT_UPLOADS_COUNT:
|
||||||
upload["_mail_info"] = sent_mail_index[normalized]
|
upload["_mail_info"] = sent_mail_index[normalized]
|
||||||
uploads_with_mail.append(upload)
|
uploads_with_mail.append(upload)
|
||||||
if len(uploads_with_mail) >= RECENT_UPLOADS_COUNT:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not uploads_with_mail:
|
if not uploads_with_mail:
|
||||||
return []
|
return [], 0
|
||||||
|
|
||||||
# Load cache and check if it's still valid
|
# Load cache and check if it's still valid
|
||||||
cache = load_commons_thumbnail_cache()
|
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:
|
def is_valid_flickr_image_url(url: str) -> bool:
|
||||||
|
|
@ -574,12 +580,16 @@ def start() -> str:
|
||||||
"""Start form."""
|
"""Start form."""
|
||||||
enwp = flask.request.args.get("enwp")
|
enwp = flask.request.args.get("enwp")
|
||||||
if not enwp:
|
if not enwp:
|
||||||
recent_uploads = get_recent_commons_uploads()
|
recent_uploads, total_uploads = get_recent_commons_uploads()
|
||||||
return flask.render_template("combined.html", recent_uploads=recent_uploads)
|
return flask.render_template(
|
||||||
|
"combined.html", recent_uploads=recent_uploads, total_uploads=total_uploads
|
||||||
|
)
|
||||||
enwp = enwp.strip()
|
enwp = enwp.strip()
|
||||||
if not enwp:
|
if not enwp:
|
||||||
recent_uploads = get_recent_commons_uploads()
|
recent_uploads, total_uploads = get_recent_commons_uploads()
|
||||||
return flask.render_template("combined.html", recent_uploads=recent_uploads)
|
return flask.render_template(
|
||||||
|
"combined.html", recent_uploads=recent_uploads, total_uploads=total_uploads
|
||||||
|
)
|
||||||
|
|
||||||
input_is = "url" if enwiki in enwp else "title"
|
input_is = "url" if enwiki in enwp else "title"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
{% if recent_uploads is defined and recent_uploads and not name %}
|
{% if recent_uploads is defined and recent_uploads and not name %}
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<h5>Recent uploads to Wikimedia Commons</h5>
|
<h5>Recent uploads to Wikimedia Commons</h5>
|
||||||
<p class="text-muted small">Photos obtained via Flickr mail requests</p>
|
<p class="text-muted small">{{ total_uploads }} photos obtained via Flickr mail requests</p>
|
||||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
|
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
|
||||||
{% for upload in recent_uploads %}
|
{% for upload in recent_uploads %}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue