Help:Toolforge/Running Pywikibot scripts

From Wikitech
Jump to navigation Jump to search

The Pywikibot framework is a Python library and collection of scripts to automate work on MediaWiki sites. This tutorial contains instructions on how to run Pywikibot's built-in scripts on Toolforge using the Toolforge jobs framework. If you want to run a script that is not included with Pywikibot itself, follow the generic Python on Toolforge documentation.


To effectively use Pywikibot on Toolforge, you need:


The provided Pywikibot image uses OAuth for authenticating with Wikimedia wikis. To set it up:

  1. Set up an owner-only OAuth credential following the instructions at mw:Manual:Pywikibot/OAuth/Wikimedia#Registering your bot with the wiki software.
  2. On Toolforge, create environment variables that contain the bot username and the four values you got when creating the OAuth credential:
    tools.mytool@tools-sgebastion-10:~$ toolforge envvars create PWB_USERNAME "Example"
    tools.mytool@tools-sgebastion-10:~$ toolforge envvars create PWB_CONSUMER_TOKEN "..."
    tools.mytool@tools-sgebastion-10:~$ toolforge envvars create PWB_CONSUMER_SECRET "..."
    tools.mytool@tools-sgebastion-10:~$ toolforge envvars create PWB_ACCESS_TOKEN "..."
    tools.mytool@tools-sgebastion-10:~$ toolforge envvars create PWB_ACCESS_SECRET "..."
  3. You are now ready to run Pywikibot scripts on Toolforge.

Running scripts

Use the toolforge jobs utility to run jobs using the jobs framework. The tool-pywikibot/pywikibot-scripts-stable:latest image is maintained by the Toolforge admin team and always points to the latest stable Pywikibot release.


To run a single job:

tools.mytool@tools-sgebastion-10:~$ toolforge jobs run --image tool-pywikibot/pywikibot-scripts-stable:latest --command "pwb -family:PROJECT -lang:LANGUAGE SCRIPT_NAME arg1 -always" JOB_NAME

for example, to run the script on Wikitech, you would use:

tools.mytool@tools-sgebastion-10:~$ toolforge jobs run --image tool-pywikibot/pywikibot-scripts-stable:latest --command "pwb -family:wikitech -lang:en redirect double -always" fix-double-redirects

You can use the --schedule option to run a job on a timer, for example every day:

tools.mytool@tools-sgebastion-10:~$ toolforge jobs run --image tool-pywikibot/pywikibot-scripts-stable:latest --command "pwb -family:PROJECT -lang:LANGUAGE SCRIPT_NAME arg1 -always" --schedule "@daily" JOB_NAME

See also

Communication and support

Support and administration of the WMCS resources is provided by the Wikimedia Foundation Cloud Services team and Wikimedia movement volunteers. Please reach out with questions and join the conversation:

Discuss and receive general support
Stay aware of critical changes and plans
Track work tasks and report bugs

Use a subproject of the #Cloud-Services Phabricator project to track confirmed bug reports and feature requests about the Cloud Services infrastructure itself

Read stories and WMCS blog posts

Read the Cloud Services Blog (for the broader Wikimedia movement, see the Wikimedia Technical Blog)