wikipedia_images.bulk_import

Bulk import of images and their metadata from English Wikipedia.

Uses the public MediaWiki Action API (JSON) at https://en.wikipedia.org/w/api.php and the Wikipedia REST API (/api/rest_v1/page/media-list). Images from the French Polynesia article and a map for each of its 10 most populated islands are downloaded to wikipedia_images/ and cached metadata is written to wikipedia_images_resources.json.

Attributes

API_URL

REST_URL

HEADERS

MAIN_PAGE

ISLANDS

_HERE

_CACHE

_IMAGES

_IMAGE_SUFFIXES

_TAGS

Functions

_text(extmetadata, key) → str

_parse_date(value) → datetime.datetime | None

list_page_images(httpx_async_client, page) → list[str]

Return the File: titles of all images on a Wikipedia page.

fetch_image_items(httpx_async_client, titles, page) → list[server.plugins.wikipedia_images.wikipedia_images_models.WikipediaImagesItem]

Fetch image metadata for File: titles (max 50 per request).

download(httpx_async_client, item) → None

Download the image to wikipedia_images/ and record its path.

bulk_import() → list[server.plugins.wikipedia_images.wikipedia_images_models.WikipediaImagesItem]

Return image records for French Polynesia plus a map per island (cached).

Module Contents

wikipedia_images.bulk_import.API_URL = 'https://en.wikipedia.org/w/api.php'
wikipedia_images.bulk_import.REST_URL = 'https://en.wikipedia.org/api/rest_v1/page/media-list/'
wikipedia_images.bulk_import.HEADERS
wikipedia_images.bulk_import.MAIN_PAGE = 'French_Polynesia'
wikipedia_images.bulk_import.ISLANDS = ('Tahiti', 'Moorea', 'Raiatea', 'Bora_Bora', 'Huahine', "Taha'a", 'Nuku_Hiva', 'Rangiroa',...
wikipedia_images.bulk_import._HERE
wikipedia_images.bulk_import._CACHE
wikipedia_images.bulk_import._IMAGES
wikipedia_images.bulk_import._IMAGE_SUFFIXES = ('.jpg', '.jpeg', '.png', '.svg', '.gif', '.webp')
wikipedia_images.bulk_import._TAGS
wikipedia_images.bulk_import._text(extmetadata: dict, key: str) → str
wikipedia_images.bulk_import._parse_date(value: str) → datetime.datetime | None
async wikipedia_images.bulk_import.list_page_images(httpx_async_client: httpx2.AsyncClient, page: str) → list[str]

Return the File: titles of all images on a Wikipedia page.

async wikipedia_images.bulk_import.fetch_image_items(httpx_async_client: httpx2.AsyncClient, titles: list[str], page: str) → list[server.plugins.wikipedia_images.wikipedia_images_models.WikipediaImagesItem]

Fetch image metadata for File: titles (max 50 per request).

async wikipedia_images.bulk_import.download(httpx_async_client: httpx2.AsyncClient, item: server.plugins.wikipedia_images.wikipedia_images_models.WikipediaImagesItem) → None

Download the image to wikipedia_images/ and record its path.

async wikipedia_images.bulk_import.bulk_import() → list[server.plugins.wikipedia_images.wikipedia_images_models.WikipediaImagesItem]

Return image records for French Polynesia plus a map per island (cached).