Wikipedia-API 0.13.0__tar.gz → 0.14.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/API.rst +80 -4
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/CHANGES.rst +7 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/CLI.rst +42 -6
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/DESIGN.rst +106 -3
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/DEVELOPMENT.rst +3 -1
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/PKG-INFO +38 -4
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/README.rst +37 -3
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/README_processed.rst +37 -3
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/SKILL.md +47 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/async.py +47 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/cli.sh +27 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/sync.py +41 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/SKILL.md +56 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/async.py +93 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/cli.sh +70 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/sync.py +81 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/SKILL.md +46 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/async.py +44 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/cli.sh +30 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/sync.py +37 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/SKILL.md +50 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/async.py +56 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/cli.sh +27 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/sync.py +49 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/SKILL.md +47 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/async.py +52 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/cli.sh +35 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/sync.py +43 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/SKILL.md +48 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/async.py +60 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/cli.sh +38 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/sync.py +53 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/example_async.py +31 -11
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/example_sync.py +33 -10
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/pyproject.toml +39 -27
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/__init__.py +23 -13
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_base_wikipedia_page.py +8 -4
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/__init__.py +20 -14
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/async_http_client.py +6 -6
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/base_http_client.py +3 -3
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/sync_http_client.py +7 -7
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_pages_dict/__init__.py +6 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/async_images_dict.py +69 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_pages_dict/async_pages_dict.py +5 -2
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_pages_dict/base_pages_dict.py +27 -2
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/images_dict.py +73 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_pages_dict/pages_dict.py +5 -2
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/__init__.py +1 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/base_params.py +4 -4
- wikipedia_api-0.14.0/wikipediaapi/_params/imageinfo_params.py +58 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_resources/async_wikipedia_resource.py +187 -36
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_resources/base_wikipedia_resource.py +125 -9
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_resources/wikipedia_resource.py +169 -33
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/__init__.py +2 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/image_info.py +44 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_version.py +1 -1
- wikipedia_api-0.14.0/wikipediaapi/async_wikipedia_image.py +282 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/async_wikipedia_page.py +15 -12
- wikipedia_api-0.14.0/wikipediaapi/cli.py +55 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/__init__.py +4 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/base.py +368 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/category_commands.py +172 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/geo_commands.py +387 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/image_commands.py +174 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/link_commands.py +213 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/page_commands.py +305 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/search_commands.py +277 -0
- wikipedia_api-0.14.0/wikipediaapi/wikipedia_image.py +242 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia_page.py +19 -13
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia_page_section.py +6 -3
- wikipedia_api-0.13.0/wikipediaapi/cli.py +0 -1481
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/.gitignore +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/LICENSE +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/coordinate_type.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/coordinates_prop.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/direction.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/geosearch_sort.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/globe.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/namespace.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/redirect_filter.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/search_info.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/search_prop.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/search_qi_profile.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/search_sort.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_enums/search_what.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/__init__.py +1 -1
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/retry_after_wait.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_http_client/retry_utils.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/coordinates_params.py +2 -2
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/geo_search_params.py +4 -4
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/images_params.py +1 -1
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/protocols.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/random_params.py +1 -1
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_params/search_params.py +5 -5
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_resources/__init__.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/coordinate.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/geo_box.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/geo_point.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/geo_search_meta.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/search_meta.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/_types/search_results.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/async_wikipedia.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/__init__.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wiki_connection_error.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wiki_http_error.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wiki_http_timeout_error.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wiki_invalid_json_error.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wiki_rate_limit_error.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/exceptions/wikipedia_exception.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/extract_format.py +0 -0
- {wikipedia_api-0.13.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia.py +1 -1
|
@@ -7,7 +7,9 @@ Wikipedia
|
|
|
7
7
|
* ``page(title, ns=Namespace.MAIN)``
|
|
8
8
|
* ``pages(titles)`` — create a ``PagesDict`` of lazy pages (no network call)
|
|
9
9
|
* ``coordinates(page, *, limit=10, primary='primary', prop=('globe',), distance_from_point=None (GeoPoint), distance_from_page=None)`` → ``list[Coordinate]``
|
|
10
|
-
* ``images(page, *, limit=10, images=None, direction=Direction.ASCENDING)`` → ``
|
|
10
|
+
* ``images(page, *, limit=10, images=None, direction=Direction.ASCENDING)`` → ``ImagesDict``
|
|
11
|
+
* ``imageinfo(image, *, prop=('url', 'width', 'height', ...), limit=1)`` → ``list[ImageInfo]``
|
|
12
|
+
* ``batch_imageinfo(images, *, prop=('url', 'width', 'height', ...), limit=1)`` → ``dict[str, list[ImageInfo]]``
|
|
11
13
|
* ``geosearch(*, coord=None (GeoPoint), page=None, bbox=None (GeoBox), radius=500, max_dim=None, sort='distance', limit=10, ns=Namespace.MAIN, prop=None)`` → ``PagesDict``
|
|
12
14
|
* ``random(*, limit=1, ns=Namespace.MAIN, filter_redir='nonredirects')`` → ``PagesDict``
|
|
13
15
|
* ``search(query, *, ns=Namespace.MAIN, limit=10, prop=None, info=None, sort='relevance')`` → ``SearchResults``
|
|
@@ -22,7 +24,9 @@ Same constructor parameters as ``Wikipedia``. All methods are coroutines
|
|
|
22
24
|
* ``page(title, ns=Namespace.MAIN)`` — returns an ``AsyncWikipediaPage`` (no network call)
|
|
23
25
|
* ``pages(titles)`` — create an ``AsyncPagesDict`` of lazy pages (no network call)
|
|
24
26
|
* ``await coordinates(page, ...)`` → ``list[Coordinate]``
|
|
25
|
-
* ``await images(page, ...)`` → ``
|
|
27
|
+
* ``await images(page, ...)`` → ``ImagesDict``
|
|
28
|
+
* ``await imageinfo(image, ...)`` → ``list[ImageInfo]``
|
|
29
|
+
* ``await batch_imageinfo(images, ...)`` → ``dict[str, list[ImageInfo]]``
|
|
26
30
|
* ``await geosearch(...)`` → ``PagesDict``
|
|
27
31
|
* ``await random(...)`` → ``PagesDict``
|
|
28
32
|
* ``await search(query, ...)`` → ``SearchResults``
|
|
@@ -46,7 +50,7 @@ WikipediaPage
|
|
|
46
50
|
* ``categories`` - categories this page belongs to ({title: ``WikipediaPage``})
|
|
47
51
|
* ``categorymembers`` - pages in this category, when ``ns=Namespace.CATEGORY`` ({title: ``WikipediaPage``})
|
|
48
52
|
* ``coordinates`` - geographic coordinates (list of ``Coordinate``); triggers ``coordinates`` API call with default params
|
|
49
|
-
* ``images`` - images/files on this page (``
|
|
53
|
+
* ``images`` - images/files on this page (``ImagesDict``); triggers ``images`` API call with default params
|
|
50
54
|
* ``geosearch_meta`` - ``GeoSearchMeta`` or ``None``; set when page came from ``geosearch()`` (plain property, no fetch)
|
|
51
55
|
* ``search_meta`` - ``SearchMeta`` or ``None``; set when page came from ``search()`` (plain property, no fetch)
|
|
52
56
|
* ``displaytitle``
|
|
@@ -87,7 +91,7 @@ return coroutines (awaitable with ``await``).
|
|
|
87
91
|
* ``await page.categories`` — awaitable property; ``{title: AsyncWikipediaPage}`` dict
|
|
88
92
|
* ``await page.categorymembers`` — awaitable property; ``{title: AsyncWikipediaPage}`` dict
|
|
89
93
|
* ``await page.coordinates`` — awaitable property; ``list[Coordinate]``
|
|
90
|
-
* ``await page.images`` — awaitable property; ``
|
|
94
|
+
* ``await page.images`` — awaitable property; ``ImagesDict``
|
|
91
95
|
* ``page.geosearch_meta`` — plain property; ``GeoSearchMeta | None`` (no await)
|
|
92
96
|
* ``page.search_meta`` — plain property; ``SearchMeta | None`` (no await)
|
|
93
97
|
* ``await page.exists()`` — coroutine method; lazily fetches ``pageid`` via ``info`` if not yet cached
|
|
@@ -103,6 +107,60 @@ WikipediaPageSection
|
|
|
103
107
|
* ``section_by_title(title)``
|
|
104
108
|
* ``full_text(level=1)`` - rendered text of this section and all descendants
|
|
105
109
|
|
|
110
|
+
WikipediaImage
|
|
111
|
+
---------------
|
|
112
|
+
Lazy representation of a Wikipedia/Commons file page. No network call is
|
|
113
|
+
made at construction time; accessing ``imageinfo`` (or any convenience
|
|
114
|
+
property derived from it) triggers the minimum API call needed.
|
|
115
|
+
|
|
116
|
+
* ``title`` — file title including the ``File:`` prefix
|
|
117
|
+
* ``language`` — two-letter language code
|
|
118
|
+
* ``namespace`` — integer namespace number (6 for files)
|
|
119
|
+
* ``pageid`` — MediaWiki page ID
|
|
120
|
+
* ``imageinfo`` — list of ``ImageInfo`` objects (lazy-fetched; triggers API call)
|
|
121
|
+
* ``url`` — full URL of the file (from first ``ImageInfo``)
|
|
122
|
+
* ``width`` — image width in pixels (from first ``ImageInfo``)
|
|
123
|
+
* ``height`` — image height in pixels (from first ``ImageInfo``)
|
|
124
|
+
* ``size`` — file size in bytes (from first ``ImageInfo``)
|
|
125
|
+
* ``mime`` — MIME type (from first ``ImageInfo``)
|
|
126
|
+
* ``mediatype`` — MediaWiki media type (from first ``ImageInfo``)
|
|
127
|
+
* ``sha1`` — SHA-1 hash of the file (from first ``ImageInfo``)
|
|
128
|
+
* ``timestamp`` — ISO 8601 timestamp of this revision (from first ``ImageInfo``)
|
|
129
|
+
* ``user`` — username of the uploader (from first ``ImageInfo``)
|
|
130
|
+
* ``descriptionurl`` — URL of the file description page (from first ``ImageInfo``)
|
|
131
|
+
* ``descriptionshorturl`` — short URL of the description page (from first ``ImageInfo``)
|
|
132
|
+
|
|
133
|
+
AsyncWikipediaImage
|
|
134
|
+
--------------------
|
|
135
|
+
Async mirror of ``WikipediaImage``. All properties that trigger network calls
|
|
136
|
+
are awaitable (use ``await``).
|
|
137
|
+
|
|
138
|
+
* ``title``, ``language``, ``namespace``, ``pageid`` — plain properties (no await)
|
|
139
|
+
* ``await imageinfo`` — awaitable property; list of ``ImageInfo`` objects
|
|
140
|
+
* ``await url`` — awaitable property; full URL of the file
|
|
141
|
+
* ``await width`` — awaitable property; image width in pixels
|
|
142
|
+
* ``await height`` — awaitable property; image height in pixels
|
|
143
|
+
* ``await size`` — awaitable property; file size in bytes
|
|
144
|
+
* ``await mime`` — awaitable property; MIME type
|
|
145
|
+
* ``await mediatype`` — awaitable property; MediaWiki media type
|
|
146
|
+
* ``await sha1`` — awaitable property; SHA-1 hash of the file
|
|
147
|
+
* ``await timestamp`` — awaitable property; ISO 8601 timestamp
|
|
148
|
+
* ``await user`` — awaitable property; username of uploader
|
|
149
|
+
* ``await descriptionurl`` — awaitable property; description page URL
|
|
150
|
+
* ``await descriptionshorturl`` — awaitable property; short description page URL
|
|
151
|
+
|
|
152
|
+
ImagesDict
|
|
153
|
+
----------
|
|
154
|
+
A ``dict[str, WikipediaImage]`` subclass with batch convenience methods.
|
|
155
|
+
|
|
156
|
+
* ``imageinfo(*, prop=_DEFAULT_PROP, limit=1)`` → ``dict[str, list[ImageInfo]]`` — batch-fetch ``imageinfo`` for all images via ``batch_imageinfo()``
|
|
157
|
+
|
|
158
|
+
AsyncImagesDict
|
|
159
|
+
---------------
|
|
160
|
+
Async mirror of ``ImagesDict``.
|
|
161
|
+
|
|
162
|
+
* ``await imageinfo(*, prop=_DEFAULT_PROP, limit=1)`` → ``dict[str, list[ImageInfo]]``
|
|
163
|
+
|
|
106
164
|
ExtractFormat
|
|
107
165
|
-------------
|
|
108
166
|
* ``WIKI`` - plain-text wiki markup (``==Heading==``)
|
|
@@ -194,6 +252,24 @@ Frozen dataclass attached to pages returned by ``search()``.
|
|
|
194
252
|
* ``wordcount: int`` — word count
|
|
195
253
|
* ``timestamp: str`` — last edit timestamp (ISO 8601)
|
|
196
254
|
|
|
255
|
+
``ImageInfo``
|
|
256
|
+
~~~~~~~~~~~~~
|
|
257
|
+
Frozen dataclass representing one file revision from ``prop=imageinfo``.
|
|
258
|
+
All fields are optional and depend on the ``iiprop`` parameter and file
|
|
259
|
+
availability.
|
|
260
|
+
|
|
261
|
+
* ``url: str | None`` — full URL of the file
|
|
262
|
+
* ``descriptionurl: str | None`` — URL of the file description page
|
|
263
|
+
* ``descriptionshorturl: str | None`` — short URL of the description page
|
|
264
|
+
* ``width: int | None`` — image width in pixels
|
|
265
|
+
* ``height: int | None`` — image height in pixels
|
|
266
|
+
* ``size: int | None`` — file size in bytes
|
|
267
|
+
* ``mime: str | None`` — MIME type (e.g. ``"image/jpeg"``)
|
|
268
|
+
* ``mediatype: str | None`` — MediaWiki media type (e.g. ``"BITMAP"``)
|
|
269
|
+
* ``sha1: str | None`` — SHA-1 hash of the file content
|
|
270
|
+
* ``timestamp: str | None`` — ISO 8601 timestamp of this revision
|
|
271
|
+
* ``user: str | None`` — username of the uploader
|
|
272
|
+
|
|
197
273
|
``SearchResults``
|
|
198
274
|
~~~~~~~~~~~~~~~~~
|
|
199
275
|
Wrapper returned by ``search()``.
|
|
@@ -15,12 +15,35 @@ Every command supports the following options:
|
|
|
15
15
|
* ``-v, --variant`` — Language variant (e.g. ``zh-cn``, ``zh-tw``)
|
|
16
16
|
* ``-f, --extract-format`` — Extraction format: ``wiki`` or ``html`` (default: ``wiki``)
|
|
17
17
|
* ``-n, --namespace`` — Wikipedia namespace number (default: ``0`` = Main)
|
|
18
|
+
* ``--max-retries`` — Maximum number of retry attempts for transient errors (HTTP 429, 5xx, timeouts, connection errors). Set to ``0`` to disable retries entirely (default: ``3``)
|
|
19
|
+
* ``--retry-wait`` — Base wait time in seconds between retries; actual wait uses exponential backoff (``retry_wait * 2^attempt``). For HTTP 429 the ``Retry-After`` header value is used instead (default: ``1.0``)
|
|
18
20
|
* ``-h, --help`` — Show help for any command
|
|
19
21
|
|
|
20
22
|
Commands that return lists also support:
|
|
21
23
|
|
|
22
24
|
* ``--json`` — Output results as JSON
|
|
23
25
|
|
|
26
|
+
Retry Configuration
|
|
27
|
+
-------------------
|
|
28
|
+
|
|
29
|
+
Control retry behavior for network issues and rate limiting:
|
|
30
|
+
|
|
31
|
+
Use custom retry settings::
|
|
32
|
+
|
|
33
|
+
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0
|
|
34
|
+
|
|
35
|
+
Disable retries entirely (fail fast on first error)::
|
|
36
|
+
|
|
37
|
+
wikipedia-api search "Python" --max-retries 0
|
|
38
|
+
|
|
39
|
+
Use aggressive retrying for unreliable connections::
|
|
40
|
+
|
|
41
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278" --max-retries 10 --retry-wait 3.0
|
|
42
|
+
|
|
43
|
+
Combine with other options::
|
|
44
|
+
|
|
45
|
+
wikipedia-api random --limit 5 --max-retries 1 --retry-wait 0.5 --language de
|
|
46
|
+
|
|
24
47
|
Getting Help
|
|
25
48
|
------------
|
|
26
49
|
|
|
@@ -173,10 +196,23 @@ Output as JSON::
|
|
|
173
196
|
|
|
174
197
|
wikipedia-api images "Python (programming language)" --json
|
|
175
198
|
|
|
199
|
+
Fetch image metadata (URL, dimensions, MIME type, uploader, etc.) with
|
|
200
|
+
the ``--imageinfo`` flag::
|
|
201
|
+
|
|
202
|
+
wikipedia-api images "Mount Everest" --imageinfo
|
|
203
|
+
|
|
204
|
+
Display imageinfo metadata as JSON::
|
|
205
|
+
|
|
206
|
+
wikipedia-api images "Mount Everest" --imageinfo --json
|
|
207
|
+
|
|
176
208
|
Limit the number of images::
|
|
177
209
|
|
|
178
210
|
wikipedia-api images "Earth" --limit 50
|
|
179
211
|
|
|
212
|
+
Combine options::
|
|
213
|
+
|
|
214
|
+
wikipedia-api images "Earth" --limit 20 --imageinfo --language de
|
|
215
|
+
|
|
180
216
|
Geosearch
|
|
181
217
|
---------
|
|
182
218
|
|
|
@@ -227,8 +263,8 @@ Complete Workflow Example
|
|
|
227
263
|
|
|
228
264
|
Fetch a page summary, then explore its sections and links::
|
|
229
265
|
|
|
230
|
-
# Get summary
|
|
231
|
-
wikipedia-api summary "Python (programming language)"
|
|
266
|
+
# Get summary with custom retry settings
|
|
267
|
+
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0
|
|
232
268
|
|
|
233
269
|
# List sections
|
|
234
270
|
wikipedia-api sections "Python (programming language)"
|
|
@@ -248,11 +284,11 @@ Fetch a page summary, then explore its sections and links::
|
|
|
248
284
|
# Show coordinates for a geographic page
|
|
249
285
|
wikipedia-api coordinates "Mount Everest"
|
|
250
286
|
|
|
251
|
-
# Search for pages near a location
|
|
252
|
-
wikipedia-api geosearch --coord "27.9881|86.9250"
|
|
287
|
+
# Search for pages near a location with aggressive retrying
|
|
288
|
+
wikipedia-api geosearch --coord "27.9881|86.9250" --max-retries 10 --retry-wait 3.0
|
|
253
289
|
|
|
254
|
-
# Search Wikipedia
|
|
255
|
-
wikipedia-api search "Mount Everest"
|
|
290
|
+
# Search Wikipedia with retries disabled
|
|
291
|
+
wikipedia-api search "Mount Everest" --max-retries 0
|
|
256
292
|
|
|
257
293
|
# Get random pages
|
|
258
294
|
wikipedia-api random --limit 3
|
|
@@ -34,6 +34,16 @@ File Layout
|
|
|
34
34
|
|
|
35
35
|
wikipediaapi/
|
|
36
36
|
├── __init__.py # Public exports
|
|
37
|
+
├── cli.py # Command line interface (main entry point)
|
|
38
|
+
├── commands/ # CLI command modules
|
|
39
|
+
│ ├── __init__.py
|
|
40
|
+
│ ├── base.py # Shared utilities and common options
|
|
41
|
+
│ ├── page_commands.py # Page content commands
|
|
42
|
+
│ ├── link_commands.py # Link-related commands
|
|
43
|
+
│ ├── category_commands.py # Category commands
|
|
44
|
+
│ ├── geo_commands.py # Geographic commands
|
|
45
|
+
│ ├── image_commands.py # Image file commands
|
|
46
|
+
│ └── search_commands.py # Search and discovery commands
|
|
37
47
|
├── _http_client/ # Transport layer package
|
|
38
48
|
│ ├── __init__.py
|
|
39
49
|
│ ├── base_http_client.py # Shared retry & config logic
|
|
@@ -52,6 +62,7 @@ File Layout
|
|
|
52
62
|
│ ├── geo_point.py # GeoPoint dataclass
|
|
53
63
|
│ ├── geo_box.py # GeoBox dataclass
|
|
54
64
|
│ ├── geo_search_meta.py # GeoSearchMeta dataclass
|
|
65
|
+
│ ├── image_info.py # ImageInfo dataclass
|
|
55
66
|
│ ├── search_meta.py # SearchMeta dataclass
|
|
56
67
|
│ └── search_results.py # SearchResults dataclass
|
|
57
68
|
├── _params/ # Query parameter dataclasses package
|
|
@@ -63,11 +74,13 @@ File Layout
|
|
|
63
74
|
│ ├── random_params.py # RandomParams
|
|
64
75
|
│ ├── search_params.py # SearchParams
|
|
65
76
|
│ └── protocols.py # Protocol constants
|
|
66
|
-
├── _pages_dict/ # PagesDict package
|
|
77
|
+
├── _pages_dict/ # PagesDict and ImagesDict package
|
|
67
78
|
│ ├── __init__.py
|
|
68
79
|
│ ├── base_pages_dict.py # Base PagesDict functionality
|
|
69
80
|
│ ├── pages_dict.py # PagesDict (sync)
|
|
70
|
-
│
|
|
81
|
+
│ ├── async_pages_dict.py # AsyncPagesDict
|
|
82
|
+
│ ├── images_dict.py # ImagesDict (sync)
|
|
83
|
+
│ └── async_images_dict.py # AsyncImagesDict
|
|
71
84
|
├── _enums/ # Enums package
|
|
72
85
|
│ ├── __init__.py
|
|
73
86
|
│ ├── coordinate_type.py # CoordinateType enum
|
|
@@ -95,6 +108,8 @@ File Layout
|
|
|
95
108
|
├── _base_wikipedia_page.py # BaseWikipediaPage (shared page state & methods)
|
|
96
109
|
├── wikipedia_page.py # WikipediaPage (lazy sync page object)
|
|
97
110
|
├── async_wikipedia_page.py # AsyncWikipediaPage (lazy async page object)
|
|
111
|
+
├── wikipedia_image.py # WikipediaImage (lazy sync file page object)
|
|
112
|
+
├── async_wikipedia_image.py # AsyncWikipediaImage (lazy async file page object)
|
|
98
113
|
├── wikipedia_page_section.py # WikipediaPageSection
|
|
99
114
|
├── extract_format.py # ExtractFormat enum (WIKI / HTML)
|
|
100
115
|
└── namespace.py # Legacy namespace module (redirects to _enums.namespace)
|
|
@@ -115,7 +130,9 @@ The inheritance chains are::
|
|
|
115
130
|
|
|
116
131
|
BaseWikipediaPage
|
|
117
132
|
├── WikipediaPage
|
|
118
|
-
|
|
133
|
+
├── AsyncWikipediaPage
|
|
134
|
+
├── WikipediaImage
|
|
135
|
+
└── AsyncWikipediaImage
|
|
119
136
|
|
|
120
137
|
Concrete clients compose one transport and one API mixin::
|
|
121
138
|
|
|
@@ -823,3 +840,89 @@ Strongly-typed enums for API parameters:
|
|
|
823
840
|
* ``geosearch_meta`` and ``search_meta`` are plain ``@property`` in both
|
|
824
841
|
sync and async — they are set by ``geosearch()`` / ``search()`` on
|
|
825
842
|
the wiki client and require no network call on the page itself.
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
Command Line Interface
|
|
846
|
+
---------------------
|
|
847
|
+
|
|
848
|
+
The CLI provides a command-line tool for querying Wikipedia using Wikipedia-API.
|
|
849
|
+
It is organized into a modular structure for better maintainability.
|
|
850
|
+
|
|
851
|
+
**Architecture**
|
|
852
|
+
|
|
853
|
+
The CLI is split into a main entry point and functional command modules::
|
|
854
|
+
|
|
855
|
+
wikipediaapi/
|
|
856
|
+
├── cli.py # Main CLI entry point (54 lines)
|
|
857
|
+
└── commands/ # CLI command modules
|
|
858
|
+
├── __init__.py
|
|
859
|
+
├── base.py # Shared utilities and common options
|
|
860
|
+
├── page_commands.py # Page content commands
|
|
861
|
+
├── link_commands.py # Link-related commands
|
|
862
|
+
├── category_commands.py # Category commands
|
|
863
|
+
├── geo_commands.py # Geographic commands
|
|
864
|
+
└── search_commands.py # Search and discovery commands
|
|
865
|
+
|
|
866
|
+
**Main Entry Point (``cli.py``)**
|
|
867
|
+
|
|
868
|
+
* Sets up the Click command group with version and help options
|
|
869
|
+
* Imports and registers all command modules
|
|
870
|
+
* Provides the ``main()`` function for the console script entry point
|
|
871
|
+
* Reduced from 1481 lines to 54 lines for better maintainability
|
|
872
|
+
|
|
873
|
+
**Base Module (``commands/base.py``)**
|
|
874
|
+
|
|
875
|
+
* Contains shared utilities: TypedDict classes, enum validators, formatters
|
|
876
|
+
* Defines common Click options used across all commands
|
|
877
|
+
* Provides helper functions for Wikipedia instance creation and page fetching
|
|
878
|
+
* Centralizes formatting functions for consistent output
|
|
879
|
+
|
|
880
|
+
**Command Modules**
|
|
881
|
+
|
|
882
|
+
Each command module groups related functionality:
|
|
883
|
+
|
|
884
|
+
* ``page_commands.py`` — ``summary``, ``text``, ``sections``, ``section``, ``page``
|
|
885
|
+
* ``link_commands.py`` — ``links``, ``backlinks``, ``langlinks``
|
|
886
|
+
* ``category_commands.py`` — ``categories``, ``categorymembers``
|
|
887
|
+
* ``geo_commands.py`` — ``coordinates``, ``images``, ``geosearch``
|
|
888
|
+
* ``search_commands.py`` — ``search``, ``random``
|
|
889
|
+
|
|
890
|
+
**Command Pattern**
|
|
891
|
+
|
|
892
|
+
Each command module follows this pattern:
|
|
893
|
+
|
|
894
|
+
1. **Business logic functions** — Pure functions that handle Wikipedia API calls
|
|
895
|
+
2. **Formatting functions** — Convert results to text/JSON output
|
|
896
|
+
3. **Click command decorators** — Define CLI interface with options and arguments
|
|
897
|
+
4. **Register function** — Registers commands with the main CLI group
|
|
898
|
+
|
|
899
|
+
**Benefits of Modular Structure**
|
|
900
|
+
|
|
901
|
+
* **Maintainable file sizes** — Each module 150-430 lines vs one 1481-line file
|
|
902
|
+
* **Logical organization** — Related commands grouped together
|
|
903
|
+
* **Easier development** — Changes to specific functionality isolated to relevant module
|
|
904
|
+
* **Better testing** — Command modules can be tested independently
|
|
905
|
+
* **Perfect backward compatibility** — All CLI commands work identically to before
|
|
906
|
+
|
|
907
|
+
**Usage Examples**
|
|
908
|
+
|
|
909
|
+
The CLI supports all original commands with identical interfaces::
|
|
910
|
+
|
|
911
|
+
wikipedia-api summary "Python (programming language)"
|
|
912
|
+
wikipedia-api links "Python (programming language)" --language cs
|
|
913
|
+
wikipedia-api categories "Python (programming language)" --json
|
|
914
|
+
wikipedia-api coordinates "Mount Everest"
|
|
915
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278"
|
|
916
|
+
wikipedia-api search "Python programming"
|
|
917
|
+
|
|
918
|
+
**Adding New Commands**
|
|
919
|
+
|
|
920
|
+
To add a new CLI command:
|
|
921
|
+
|
|
922
|
+
1. Choose the appropriate command module based on functionality
|
|
923
|
+
2. Add business logic function (following existing patterns)
|
|
924
|
+
3. Add formatting function for output
|
|
925
|
+
4. Add Click command with proper options and documentation
|
|
926
|
+
5. Register the command in the module's ``register_commands()`` function
|
|
927
|
+
|
|
928
|
+
The modular structure makes it easy to extend the CLI while maintaining clean organization.
|
|
@@ -10,11 +10,13 @@ Prerequisites
|
|
|
10
10
|
|
|
11
11
|
Makefile targets
|
|
12
12
|
-----------------
|
|
13
|
-
* ``make run-
|
|
13
|
+
* ``make run-type-check`` - type checks source code (runs ``uv run ty check wikipediaapi/``)
|
|
14
|
+
* ``make run-ruff`` - lints and checks formatting (runs ``ruff check`` and ``ruff format --check``)
|
|
14
15
|
* ``make requirements-all`` - install all requirements
|
|
15
16
|
* ``make requirements`` - install package requirements
|
|
16
17
|
* ``make requirements-dev`` - install development requirements
|
|
17
18
|
* ``make run-tests`` - run unit tests (pytest)
|
|
19
|
+
* ``make run-tests-integration`` - run VCR integration tests (pytest)
|
|
18
20
|
* ``make run-coverage`` - run code coverage (pytest-cov)
|
|
19
21
|
* ``make pypi-html`` - generates single HTML documentation into ``pypi-doc.html``
|
|
20
22
|
* ``make html`` - generates HTML documentation similar to RTFD into folder ``_build/html/``
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Wikipedia-API
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: Python Wrapper for Wikipedia
|
|
5
5
|
Project-URL: Homepage, https://github.com/martin-majlis/Wikipedia-API
|
|
6
6
|
Project-URL: Repository, https://github.com/martin-majlis/Wikipedia-API
|
|
@@ -562,7 +562,8 @@ How To Get Page Images
|
|
|
562
562
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
563
563
|
|
|
564
564
|
To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
565
|
-
``images`` property on the page.
|
|
565
|
+
``images`` property on the page. The ``images`` method returns an ``ImagesDict``
|
|
566
|
+
with ``WikipediaImage`` objects that provide lazy access to image metadata.
|
|
566
567
|
|
|
567
568
|
**Synchronous**
|
|
568
569
|
|
|
@@ -570,12 +571,29 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
570
571
|
|
|
571
572
|
page = wiki_wiki.page('London')
|
|
572
573
|
imgs = wiki_wiki.images(page)
|
|
573
|
-
for title in imgs:
|
|
574
|
+
for title, img in imgs.items():
|
|
574
575
|
print(title)
|
|
575
576
|
|
|
576
577
|
# Or via the page property:
|
|
577
578
|
imgs = page.images
|
|
578
579
|
|
|
580
|
+
To fetch detailed metadata about images (URL, dimensions, MIME type, etc.),
|
|
581
|
+
use the ``imageinfo()`` method on the ``ImagesDict``:
|
|
582
|
+
|
|
583
|
+
.. code-block:: python
|
|
584
|
+
|
|
585
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
586
|
+
for title, img in page.images.items():
|
|
587
|
+
# Lazy properties trigger imageinfo API call on first access:
|
|
588
|
+
print(f"{title}: {img.url}, {img.width}x{img.height}, {img.mime}")
|
|
589
|
+
|
|
590
|
+
# Or batch-fetch imageinfo for all images at once:
|
|
591
|
+
infos = page.images.imageinfo()
|
|
592
|
+
for title, info_list in infos.items():
|
|
593
|
+
if info_list:
|
|
594
|
+
info = info_list[0]
|
|
595
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
596
|
+
|
|
579
597
|
**Asynchronous**
|
|
580
598
|
|
|
581
599
|
.. code-block:: python
|
|
@@ -583,9 +601,25 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
583
601
|
async def main():
|
|
584
602
|
page = wiki_wiki.page('London')
|
|
585
603
|
imgs = await wiki_wiki.images(page)
|
|
586
|
-
for title in imgs:
|
|
604
|
+
for title, img in imgs.items():
|
|
587
605
|
print(title)
|
|
588
606
|
|
|
607
|
+
# Fetch image metadata with lazy properties:
|
|
608
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
609
|
+
for title, img in (await page.images).items():
|
|
610
|
+
url = await img.url
|
|
611
|
+
width = await img.width
|
|
612
|
+
height = await img.height
|
|
613
|
+
mime = await img.mime
|
|
614
|
+
print(f"{title}: {url}, {width}x{height}, {mime}")
|
|
615
|
+
|
|
616
|
+
# Or batch-fetch imageinfo for all images:
|
|
617
|
+
infos = await (await page.images).imageinfo()
|
|
618
|
+
for title, info_list in infos.items():
|
|
619
|
+
if info_list:
|
|
620
|
+
info = info_list[0]
|
|
621
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
622
|
+
|
|
589
623
|
How To Search Nearby Pages (Geosearch)
|
|
590
624
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
591
625
|
|
|
@@ -529,7 +529,8 @@ How To Get Page Images
|
|
|
529
529
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
530
530
|
|
|
531
531
|
To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
532
|
-
``images`` property on the page.
|
|
532
|
+
``images`` property on the page. The ``images`` method returns an ``ImagesDict``
|
|
533
|
+
with ``WikipediaImage`` objects that provide lazy access to image metadata.
|
|
533
534
|
|
|
534
535
|
**Synchronous**
|
|
535
536
|
|
|
@@ -537,12 +538,29 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
537
538
|
|
|
538
539
|
page = wiki_wiki.page('London')
|
|
539
540
|
imgs = wiki_wiki.images(page)
|
|
540
|
-
for title in imgs:
|
|
541
|
+
for title, img in imgs.items():
|
|
541
542
|
print(title)
|
|
542
543
|
|
|
543
544
|
# Or via the page property:
|
|
544
545
|
imgs = page.images
|
|
545
546
|
|
|
547
|
+
To fetch detailed metadata about images (URL, dimensions, MIME type, etc.),
|
|
548
|
+
use the ``imageinfo()`` method on the ``ImagesDict``:
|
|
549
|
+
|
|
550
|
+
.. code-block:: python
|
|
551
|
+
|
|
552
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
553
|
+
for title, img in page.images.items():
|
|
554
|
+
# Lazy properties trigger imageinfo API call on first access:
|
|
555
|
+
print(f"{title}: {img.url}, {img.width}x{img.height}, {img.mime}")
|
|
556
|
+
|
|
557
|
+
# Or batch-fetch imageinfo for all images at once:
|
|
558
|
+
infos = page.images.imageinfo()
|
|
559
|
+
for title, info_list in infos.items():
|
|
560
|
+
if info_list:
|
|
561
|
+
info = info_list[0]
|
|
562
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
563
|
+
|
|
546
564
|
**Asynchronous**
|
|
547
565
|
|
|
548
566
|
.. code-block:: python
|
|
@@ -550,9 +568,25 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
550
568
|
async def main():
|
|
551
569
|
page = wiki_wiki.page('London')
|
|
552
570
|
imgs = await wiki_wiki.images(page)
|
|
553
|
-
for title in imgs:
|
|
571
|
+
for title, img in imgs.items():
|
|
554
572
|
print(title)
|
|
555
573
|
|
|
574
|
+
# Fetch image metadata with lazy properties:
|
|
575
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
576
|
+
for title, img in (await page.images).items():
|
|
577
|
+
url = await img.url
|
|
578
|
+
width = await img.width
|
|
579
|
+
height = await img.height
|
|
580
|
+
mime = await img.mime
|
|
581
|
+
print(f"{title}: {url}, {width}x{height}, {mime}")
|
|
582
|
+
|
|
583
|
+
# Or batch-fetch imageinfo for all images:
|
|
584
|
+
infos = await (await page.images).imageinfo()
|
|
585
|
+
for title, info_list in infos.items():
|
|
586
|
+
if info_list:
|
|
587
|
+
info = info_list[0]
|
|
588
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
589
|
+
|
|
556
590
|
How To Search Nearby Pages (Geosearch)
|
|
557
591
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
558
592
|
|
|
@@ -529,7 +529,8 @@ How To Get Page Images
|
|
|
529
529
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
530
530
|
|
|
531
531
|
To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
532
|
-
``images`` property on the page.
|
|
532
|
+
``images`` property on the page. The ``images`` method returns an ``ImagesDict``
|
|
533
|
+
with ``WikipediaImage`` objects that provide lazy access to image metadata.
|
|
533
534
|
|
|
534
535
|
**Synchronous**
|
|
535
536
|
|
|
@@ -537,12 +538,29 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
537
538
|
|
|
538
539
|
page = wiki_wiki.page('London')
|
|
539
540
|
imgs = wiki_wiki.images(page)
|
|
540
|
-
for title in imgs:
|
|
541
|
+
for title, img in imgs.items():
|
|
541
542
|
print(title)
|
|
542
543
|
|
|
543
544
|
# Or via the page property:
|
|
544
545
|
imgs = page.images
|
|
545
546
|
|
|
547
|
+
To fetch detailed metadata about images (URL, dimensions, MIME type, etc.),
|
|
548
|
+
use the ``imageinfo()`` method on the ``ImagesDict``:
|
|
549
|
+
|
|
550
|
+
.. code-block:: python
|
|
551
|
+
|
|
552
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
553
|
+
for title, img in page.images.items():
|
|
554
|
+
# Lazy properties trigger imageinfo API call on first access:
|
|
555
|
+
print(f"{title}: {img.url}, {img.width}x{img.height}, {img.mime}")
|
|
556
|
+
|
|
557
|
+
# Or batch-fetch imageinfo for all images at once:
|
|
558
|
+
infos = page.images.imageinfo()
|
|
559
|
+
for title, info_list in infos.items():
|
|
560
|
+
if info_list:
|
|
561
|
+
info = info_list[0]
|
|
562
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
563
|
+
|
|
546
564
|
**Asynchronous**
|
|
547
565
|
|
|
548
566
|
.. code-block:: python
|
|
@@ -550,9 +568,25 @@ To get images (files) used on a page, use ``images()`` on the wiki client or the
|
|
|
550
568
|
async def main():
|
|
551
569
|
page = wiki_wiki.page('London')
|
|
552
570
|
imgs = await wiki_wiki.images(page)
|
|
553
|
-
for title in imgs:
|
|
571
|
+
for title, img in imgs.items():
|
|
554
572
|
print(title)
|
|
555
573
|
|
|
574
|
+
# Fetch image metadata with lazy properties:
|
|
575
|
+
page = wiki_wiki.page('Python_(programming_language)')
|
|
576
|
+
for title, img in (await page.images).items():
|
|
577
|
+
url = await img.url
|
|
578
|
+
width = await img.width
|
|
579
|
+
height = await img.height
|
|
580
|
+
mime = await img.mime
|
|
581
|
+
print(f"{title}: {url}, {width}x{height}, {mime}")
|
|
582
|
+
|
|
583
|
+
# Or batch-fetch imageinfo for all images:
|
|
584
|
+
infos = await (await page.images).imageinfo()
|
|
585
|
+
for title, info_list in infos.items():
|
|
586
|
+
if info_list:
|
|
587
|
+
info = info_list[0]
|
|
588
|
+
print(f"{title}: {info.url}, {info.width}x{info.height}")
|
|
589
|
+
|
|
556
590
|
How To Search Nearby Pages (Geosearch)
|
|
557
591
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
558
592
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: category-deep-dive
|
|
3
|
+
description: Traverse a Wikipedia category tree, listing articles and subcategories
|
|
4
|
+
at each level. Use when you want to explore the full scope of a topic area or build
|
|
5
|
+
a hierarchical index of pages under a category.
|
|
6
|
+
argument-hint: [Category:Name] [max-depth]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Category Deep Dive
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Fetch a Wikipedia category page and walk its member tree recursively:
|
|
14
|
+
|
|
15
|
+
1. **Category page** — verify it exists and report direct member counts
|
|
16
|
+
2. **Direct members** — list articles and subcategories at depth 0
|
|
17
|
+
3. **Recursion** — descend into each subcategory up to `MAX_LEVEL` deep
|
|
18
|
+
|
|
19
|
+
## When to use
|
|
20
|
+
|
|
21
|
+
- You want to enumerate all pages belonging to a broad topic
|
|
22
|
+
- You are building a dataset or index from a Wikipedia category tree
|
|
23
|
+
- You need to understand the sub-structure of a large category
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Description | Default |
|
|
28
|
+
| ----------- | ------------------------------------------------- | -------------------- |
|
|
29
|
+
| `CATEGORY` | Full category title including `Category:` prefix | `"Category:Physics"` |
|
|
30
|
+
| `MAX_LEVEL` | Maximum recursion depth (0 = direct members only) | `1` |
|
|
31
|
+
| `language` | Wikipedia language edition | `en` |
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
- Sync Python: [sync.py](sync.py)
|
|
36
|
+
- Async Python: [async.py](async.py)
|
|
37
|
+
- CLI: [cli.sh](cli.sh)
|
|
38
|
+
|
|
39
|
+
## Notes
|
|
40
|
+
|
|
41
|
+
- Category pages have namespace `14` (`Namespace.CATEGORY`); check `page.ns` to
|
|
42
|
+
distinguish subcategories from articles when recursing.
|
|
43
|
+
- `categorymembers` is a lazy property — each subcategory you recurse into triggers
|
|
44
|
+
a new API call.
|
|
45
|
+
- Large categories (e.g. `Category:Living people`) can have thousands of members;
|
|
46
|
+
use `MAX_LEVEL = 0` and paginate carefully to avoid very long runs.
|
|
47
|
+
- CLI `--max-level` maps directly to the recursion depth parameter.
|