https://github.com/kenny2github/mw-api-client
A Pythonic way to access the MediaWiki API.
https://github.com/kenny2github/mw-api-client
Last synced: 8 months ago
JSON representation
A Pythonic way to access the MediaWiki API.
- Host: GitHub
- URL: https://github.com/kenny2github/mw-api-client
- Owner: Kenny2github
- License: mit
- Created: 2017-09-20T11:25:10.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-24T09:43:34.000Z (over 1 year ago)
- Last Synced: 2025-04-09T23:46:03.596Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 190 KB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
A really simple MediaWiki API client.
Can use most MediaWiki API modules.
Requires the ``requests`` library.
http://www.mediawiki.org/
Installation
============
To install the latest stable version::
pip install -U mw-api-client
To install the latest development (likely unstable) version::
git clone https://github.com/Kenny2github/mw-api-client.git
cd mw-api-client
python setup.py install
Example Usage
=============
.. code-block:: python
import mw_api_client as mw
Get a page:
.. code-block:: python
wp = mw.Wiki("https://en.wikipedia.org/w/api.php", "MyCoolBot/0.0.0")
wp.login("kenny2wiki", password)
sandbox = wp.page("User:Kenny2wiki/sandbox")
Edit page:
.. code-block:: python
# Get the page
contents = sandbox.read()
# Change
contents += "\n This is a test!"
summary = "Made a test edit"
# Submit
sandbox.edit(contents, summary)
List pages in category:
.. code-block:: python
for page in wp.category("Redirects").categorymembers():
print(page.title)
Remove all uses of a template:
.. code-block:: python
stub = wp.template("Stub")
# Pages that transclude stub, main namespace only
target_pages = list(stub.transclusions(namespace=0))
# Sort by title because it's prettier that way
target_pages.sort(key=lambda p: p.title)
for page in target_pages:
page.replace("{{stub}}", "")
Patrol all recent changes in the Help namespace:
.. code-block:: python
rcs = wp.recentchanges(rcnamespace=12)
for rc in rcs:
rc.patrol()
Made by Kenny2github, based off of ~blob8108's Scratch Wiki API client.
MIT Licensed.