On This Day: serve sharp images (originalimage, not the 330px thumbnail)

The Wikimedia feed's thumbnail is 330px, which upscales blurry in our hero. Use
originalimage.source instead — it's reliably sharp. (Can't just request a bigger
thumbnail width: for very large source images Wikimedia only serves pre-generated
bucket sizes and 400s on arbitrary widths — e.g. 500px ok, 800/1024px fail.)

- onthisday._best_image() prefers originalimage, falls back to the thumbnail.
- scripts/otd_image_upsize_backfill.py re-fetches each stored MM-DD and upgrades
  image_url in onthisday_pool + daily_onthisday in place (ran on host: pool + 6
  daily rows now sharp; today's hero verified 200). Only the /onthisday hero
  loads this image (home card is text-only), so larger files are a single-page,
  one-time load.
- test_best_image locks the prefer-original/fallback behavior.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-27 17:07:37 -04:00
parent e3e6f24753
commit 6c10ad99a9
3 changed files with 75 additions and 1 deletions
+12
View File
@@ -76,3 +76,15 @@ def test_tone_filter_llm_narrows(conn):
kept = onthisday._tone_filter([dict(e) for e in FAKE], client=FakeClient())
# keyword floor drops the invasion (3 remain), then the LLM narrows to 1
assert len(kept) == 1 and kept[0]["year"] == 1611
def test_best_image_prefers_original_over_thumbnail():
# the 330px thumbnail upscales (blurry); originalimage is reliably sharp → prefer it
page = {
"thumbnail": {"source": "https://x/thumb/Foo.jpg/330px-Foo.jpg", "width": 330},
"originalimage": {"source": "https://x/thumb/Foo.jpg/3840px-Foo.jpg", "width": 7000},
}
assert onthisday._best_image(page) == "https://x/thumb/Foo.jpg/3840px-Foo.jpg"
# falls back to the thumbnail when there's no originalimage, and to None when neither exists
assert onthisday._best_image({"thumbnail": {"source": "https://x/330px-Foo.jpg"}}) == "https://x/330px-Foo.jpg"
assert onthisday._best_image({}) is None