Fix Wikipedia Commons thumbnail URLs: 400px -> 500px (valid size)
Browse files- Bumped pithumbsize from 400 to 500 in REST API call
- Changed fallback Commons URL construction to use 500px-
- Rewrote 78 cached image URLs in both caches to 500px
Root cause: Wikipedia Commons restricted /Npx- thumbnail sizes;
only 500px and 1280px are accepted now (400px returns HTTP 400).
- .image_cache.json +0 -0
- .llm_cache.json +0 -0
- src/services/recommender.py +3 -3
.image_cache.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.llm_cache.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/services/recommender.py
CHANGED
|
@@ -242,7 +242,7 @@ def _fetch_wiki_image(name: str, city: str = "") -> str:
|
|
| 242 |
if source:
|
| 243 |
return source
|
| 244 |
# Article exists but has no thumbnail — try pageimages API instead
|
| 245 |
-
img_url = f"https://en.wikipedia.org/w/api.php?{urllib.parse.urlencode({'action': 'query', 'titles': title, 'prop': 'pageimages', 'pithumbsize':
|
| 246 |
img_data = _http_get_json(img_url, timeout=10)
|
| 247 |
if img_data:
|
| 248 |
pages = img_data.get("query", {}).get("pages", {})
|
|
@@ -400,7 +400,7 @@ def _fetch_commons_image(name: str, city: str = "", country: str = "") -> str:
|
|
| 400 |
filename = title.replace("File:", "").strip()
|
| 401 |
safe = filename.replace(" ", "_")
|
| 402 |
md5 = hashlib.md5(safe.encode()).hexdigest()
|
| 403 |
-
return f"https://upload.wikimedia.org/wikipedia/commons/thumb/{md5[0]}/{md5[:2]}/{safe}/
|
| 404 |
return ""
|
| 405 |
|
| 406 |
|
|
@@ -468,7 +468,7 @@ def _fetch_unsplash_api_image(name: str, city: str = "", country: str = "") -> s
|
|
| 468 |
data = json.loads(resp.read().decode())
|
| 469 |
results = data.get("results", [])
|
| 470 |
if results:
|
| 471 |
-
# Use small size (
|
| 472 |
return results[0]["urls"]["small"]
|
| 473 |
except Exception:
|
| 474 |
pass
|
|
|
|
| 242 |
if source:
|
| 243 |
return source
|
| 244 |
# Article exists but has no thumbnail — try pageimages API instead
|
| 245 |
+
img_url = f"https://en.wikipedia.org/w/api.php?{urllib.parse.urlencode({'action': 'query', 'titles': title, 'prop': 'pageimages', 'pithumbsize': 500, 'format': 'json'})}"
|
| 246 |
img_data = _http_get_json(img_url, timeout=10)
|
| 247 |
if img_data:
|
| 248 |
pages = img_data.get("query", {}).get("pages", {})
|
|
|
|
| 400 |
filename = title.replace("File:", "").strip()
|
| 401 |
safe = filename.replace(" ", "_")
|
| 402 |
md5 = hashlib.md5(safe.encode()).hexdigest()
|
| 403 |
+
return f"https://upload.wikimedia.org/wikipedia/commons/thumb/{md5[0]}/{md5[:2]}/{safe}/500px-{safe}"
|
| 404 |
return ""
|
| 405 |
|
| 406 |
|
|
|
|
| 468 |
data = json.loads(resp.read().decode())
|
| 469 |
results = data.get("results", [])
|
| 470 |
if results:
|
| 471 |
+
# Use small size (500px wide) — perfect for cards
|
| 472 |
return results[0]["urls"]["small"]
|
| 473 |
except Exception:
|
| 474 |
pass
|