Add Flickr search term override field

Allow users to edit the Flickr search query without changing the
Wikipedia article. Shows a text field with the current search term
(including quotes for phrase search) that can be modified and
re-submitted. The search term persists across pagination and photo
selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-02-08 13:42:18 +00:00
parent 57b2e474df
commit 7b741e951f
2 changed files with 32 additions and 12 deletions

12
main.py
View file

@ -491,7 +491,7 @@ def is_valid_flickr_image_url(url: str) -> bool:
def search_flickr(search_term: str, page: int = 1) -> SearchResult:
"""Search Flickr for photos matching the search term."""
encoded_term = quote(f'"{search_term}"')
encoded_term = quote(search_term)
url = f"https://flickr.com/search/?view_all=1&text={encoded_term}&page={page}"
response = requests.get(url, headers=BROWSER_HEADERS)
@ -711,20 +711,24 @@ def start() -> str:
# Get category param if coming from category search
cat = flask.request.args.get("cat")
# Allow overriding the Flickr search term (default includes quotes for phrase search)
flickr_search = flask.request.args.get("flickr_search") or f'"{name}"'
flickr_url = flask.request.args.get("flickr")
if not flickr_url:
# Search Flickr for photos
page = flask.request.args.get("page", 1, type=int)
page = max(1, page) # Ensure page is at least 1
if page == 1:
log_interaction("search_article", query=name, wikipedia_url=wikipedia_url)
search_result = search_flickr(name, page)
log_interaction("search_article", query=flickr_search, wikipedia_url=wikipedia_url)
search_result = search_flickr(flickr_search, page)
return flask.render_template(
"combined.html",
name=name,
enwp=enwp,
search_result=search_result,
cat=cat,
flickr_search=flickr_search,
)
if "/in/" in flickr_url:
@ -778,6 +782,7 @@ def start() -> str:
flickr_user_url=flickr_user_url,
cat=cat,
previous_messages=previous_messages,
flickr_search=flickr_search,
)
log_interaction(
@ -818,6 +823,7 @@ def start() -> str:
flickr_user_url=flickr_user_url,
cat=cat,
previous_messages=previous_messages,
flickr_search=flickr_search,
)