diff --git a/main.py b/main.py index e2aef86..31fc79a 100755 --- a/main.py +++ b/main.py @@ -354,6 +354,7 @@ class CategoryResult: articles: list[ArticleWithoutImage] gcmcontinue: str | None + error: str | None = None # Common non-content images to ignore when checking if an article has images @@ -435,6 +436,7 @@ def get_articles_without_images( articles_without_images: list[ArticleWithoutImage] = [] seen_pageids: set[int] = set() next_gcmcontinue: str | None = None + error: str | None = None # Build initial continue params from the external pagination token continue_params: dict[str, str] = {} @@ -451,8 +453,21 @@ def get_articles_without_images( ) response.raise_for_status() data = response.json() + if api_error := data.get("error"): + raise requests.RequestException( + f"{api_error.get('code', 'unknown')}: " + f"{api_error.get('info', 'unknown Wikipedia API error')}" + ) except (requests.RequestException, json.JSONDecodeError) as e: print(f"Wikipedia API error: {e}") + if articles_without_images: + error = ( + "Wikipedia stopped responding before the whole category could " + "be checked. Showing partial results. " + f"Wikipedia API error: {e}" + ) + else: + error = f"Unable to load articles. Wikipedia API error: {e}" break pages = data.get("query", {}).get("pages", {}) @@ -491,6 +506,7 @@ def get_articles_without_images( return CategoryResult( articles=articles_without_images, gcmcontinue=next_gcmcontinue, + error=error, ) @@ -758,6 +774,7 @@ def start() -> str: "combined.html", name=name, enwp=enwp, + wikipedia_url=wikipedia_url, search_result=search_result, cat=cat, flickr_search=flickr_search, @@ -890,6 +907,7 @@ def category_search() -> str: category_name=category_name, articles=result.articles, gcmcontinue=result.gcmcontinue, + error=result.error, ) diff --git a/templates/category.html b/templates/category.html index 62fcb1a..2fe8df8 100644 --- a/templates/category.html +++ b/templates/category.html @@ -50,7 +50,7 @@ {% endif %} - {% else %} + {% elif not error %}
Wikipedia article: {{ name }}
+Wikipedia article: {{ name }}
{% if wikipedia_extract %}{{ wikipedia_extract }}
{% endif %}