Pywikibot

From Wikimedia Belgium
Jump to navigation Jump to search
Language: English • Nederlands

Pywikibot is a way to automatically edit Wikimedia projects, via automated Python scripts.

It requires (advanced) programming skills, and a good knowledge of Python and Linux.

Prerequisites[edit]

You can access Pywikibot via a local shell script, Toolforge, or via PAWS (web interface). Complexity decreases from left to right.

Aspect Shell script Toolforge PAWS Jupyter notebook
Platform Linux client Cloud platform Web interface
Prerequisites Install Pywikibot Configure Pywikibot None
Login mechanism Local shell Remote shell Webpage
Authentication Username and password Developer account
ssh
Wikimedia account
OAuth
New programs
  • Design program logic
  • Write a Python script

Remarks:

  1. For Toolforge you require a separate developers account
  2. PAWS is much simpler to implement (you can concentrate on the Python coding; you do not need to setup a Linux client)

Install[edit]

See Wikidata:Pywikibot - Python 3 Tutorial

Configure[edit]

vi user-config.py
user_script_paths = ['/home/userx/userscripts']  # type: List[str]

To run Pywikibot scripts you might need to define the pwb command:

vi .bash_aliases
alias pwb='/users/geertivp/pywikibot/pwb.py'

Upgrade[edit]

From time to time you can upgrade your environment, so ensure having an up-to-date installation.

In case you get errors, you could try a new installation.

pip3 install --upgrade pip
cd pywikibot
git pull origin stable --recurse-submodules

Credentials[edit]

Either:

  • Local password in a special (hidden) configuration file
  • Gerrit developers account
  • OAuth (SUL single signon)

Example scripts[edit]

Gerrit[edit]

Folder scripts: (preinstalled scripts)

pwb create_isbn_edition

GitHub[edit]

Folder scripts/userscripts:

Private[edit]

Folder scripts/userscripts:

Optional[edit]

  • a bot account; this is a user account with a bot flag, that allows for higher transaction rates and volumes

Alternatives[edit]

A combination of:

These solutions could be much simpler to use (don't require programming, or installing, and configuring tools). Can be used as a prototype, or a proof of concept for a more complicated tool. But it incurs (more) manual operations, and possibly human errors.

Related tools[edit]

See also[edit]