Serve the picks from the API, so the live picker reads them

The picker read circuits/photos.json and seasons/photos.json relative to
itself. The API serves only /examples/, so the live page showed two HTTP
404 errors and a "Load it from disk" box for each.

The API now serves both picks files, read-only, at /picks/circuits.json
and /picks/seasons.json. Each answer is the file as the poster service
has it loaded, from the same loader it draws from: the notes first, then
the entries, a refused entry left out. The root route lists both routes.

The picker reads them from the API its site picks. Only a page opened
from a working copy (file:, or a loopback host) falls back to the
repository's files. A failure names each address and why.

Builds: docs/posters.md, Picking photos, as written in 780984064f (the lead's lines 1-4 of 2026-11-30 and answers Q1, Q2)

Claude-Session: https://claude.ai/code/session_01JG73KFhbaNj3tyJ8tKmE3W
This commit is contained in:
2026-11-30 10:18:16 +01:00
parent 780984064f
commit 250828710c
7 changed files with 148 additions and 51 deletions
+28
View File
@@ -3,6 +3,7 @@
Standard library only (no PIL, no numpy), so the merge check runs it as it is.
"""
import json
import os
import tempfile
import unittest
from pathlib import Path
@@ -102,6 +103,33 @@ class CreditAndLicenceTest(unittest.TestCase):
for name in ("circuits/photos.json", "seasons/photos.json"):
self.assertEqual(ps.read_picks(ROOT / name).get("$comment"), None, name)
def test_the_picks_routes_answer_the_picks_as_the_service_has_them_loaded(self):
photo = {"file": "A.jpg", "licence": "CC BY 4.0", "author": "A", "credit": "Photo: A", "date": "2020"}
refused = {"use": "satellite"}
cases = [
# (route, the file the poster service reads, a pick's key in it)
("/picks/circuits.json", "circuits/photos.json", "a/b/c/2004-"),
("/picks/seasons.json", "seasons/photos.json", "2024"),
]
self.assertEqual(sorted(ps.PICKS_ROUTES), sorted(route for route, _, _ in cases))
with tempfile.TemporaryDirectory() as kept:
root = Path(kept)
picks = ps.Picks(root)
for route, name, key in cases:
path = ps.PICKS_ROUTES[route]
self.assertEqual(path, Path(name), route)
(root / name).parent.mkdir()
(root / name).write_text(json.dumps({"$comment": f"a note on {name}", key: photo, "x": refused}))
os.utime(root / name, (1, 1))
with self.assertLogs(ps.logger, "ERROR"): # the refused entry, logged once when read
self.assertEqual(picks.entries(path), {key: photo}, route) # what the service draws from
answer = picks.answer(path)
self.assertEqual(list(answer), ["$comment", key], route) # its notes first, the refused one left out
self.assertEqual(answer, {"$comment": f"a note on {name}", key: photo}, route)
(root / name).write_text(json.dumps({key: {"use": "map"}}))
os.utime(root / name, (2, 2)) # a changed file is read again
self.assertEqual(picks.answer(path), {key: {"use": "map"}}, route)
def test_licences_name_every_source_and_the_pictures_rule(self):
licences = ps.licences()
self.assertEqual([entry["licence"] for entry in licences["pictures"]["licences"]],