33 releases

0.7.0-rc.3 Nov 23, 2024
0.7.0-rc.2 Jun 13, 2024
0.6.1 Jan 7, 2024
0.6.0 Dec 15, 2023
0.3.2 Nov 22, 2021

#759 in Web programming

Download history 115/week @ 2024-08-22 86/week @ 2024-08-29 32/week @ 2024-09-05 42/week @ 2024-09-12 81/week @ 2024-09-19 83/week @ 2024-09-26 87/week @ 2024-10-03 101/week @ 2024-10-10 50/week @ 2024-10-17 38/week @ 2024-10-24 44/week @ 2024-10-31 48/week @ 2024-11-07 43/week @ 2024-11-14 143/week @ 2024-11-21 55/week @ 2024-11-28 31/week @ 2024-12-05

279 downloads per month

GPL-3.0-or-later

570KB
11K SLoC

mwbot

crates.io docs.rs docs (main) pipeline status coverage report

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:

wiki_url = "https://en.wikipedia.org/w/"

If want to authenticate, add an auth section:

[auth]
username = "Example"
oauth2_token = "[...]"

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 = mwbot::Bot::from_default_config().await.unwrap();
let page = bot.page("Rust (programming language)")?;
let html = page.html().await?.into_mutable();
// The lead section is the second p tag in the first section
let lead = html.select("section > p")[1].text_contents();
assert!(lead.starts_with("Rust is a multi-paradigm, general-purpose programming language"));

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 = mwbot::Bot::from_default_config().await.unwrap();
let page = bot.page("Project:Sandbox")?;
let wikitext = "This is a test edit!";
page.save(wikitext, &SaveOptions::summary("test edit!")).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.

Dependencies

~16–30MB
~437K SLoC