mwbot
A MediaWiki bot and tool framework
mwbot
aims to provide a batteries-included framework for building bots
and tools for MediaWiki wikis. It builds on top of the mwapi
and parsoid crates, which offer lower-level APIs.
Quickstart
Configuration
Create a ~/.config/mwbot.toml
file with the following structure:
= "https://en.wikipedia.org/w/api.php"
= "https://en.wikipedia.org/api/rest_v1"
If want to authenticate, add an auth section:
[]
= "Example"
= "[...]"
See the OAuth documentation for how to get an OAuth 2 token. Using an owner-only consumer is the easiest way to do so.
Reading a page
let bot = from_default_config.await.unwrap;
let page = bot.page?;
let html = page.html.await?.into_mutable;
// The lead section is the second p tag in the first section
let lead = html.select.text_contents;
assert!;
Using Bot::from_default_config()
will look in the current directory
for mwbot.toml
before looking in the user's config directory. A
custom path can be specified by using Bot::from_config(...)
.
Editing a page
let bot = from_default_config.await.unwrap;
let page = bot.page?;
let wikitext = "This is a test edit!";
page.save.await?;
Page.save()
accepts both HTML and wikitext and supports the {{nobots}}
exclusion mechanism, among other features.
Next steps
Try using one of the offered page generators to fetch and operate on multiple pages.
Contributing
mwbot
is the flagship crate of the mwbot-rs
project.
We're always looking for new contributors, please reach out
if you're interested!
License
This crate is released under GPL-3.0-or-later. See COPYING for details.