Help:Toolforge/Running Pywikibot scripts
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.
Prerequisites
To effectively use Pywikibot on Toolforge, you need:
- Access to a tool account on Toolforge. See Help:Toolforge/Quickstart to learn how to set it up and use. Note that to use Toolforge you need a beginner-level understanding of Linux terminal, SSH (see Internet Technologies/SSH), and Bash (see Bash Shell Scripting).
- Basic familiarity with Python and Pywikibot. You don't need to know how to program in Python but it helps to understand how to run Python scripts. To learn Python, see Non-Programmer's Tutorial for Python 3 or The Python Tutorial in Python documentation.For information about Pywikibot, see Manual:Pywikibot.
Setup
The provided Pywikibot image uses OAuth for authenticating with Wikimedia wikis. To set it up:
- Set up an owner-only OAuth 1.0a credential following the instructions at mw:Manual:Pywikibot/OAuth/Wikimedia#Registering your bot with the wiki software. The required dependencies are already installed and the configuration is included in the image.
- 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 "..."
- 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.
Examples
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 redirect.py 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
- Help:Toolforge/Running Pywikibot scripts (advanced)
- Toolforge admin documentation for maintaining the image
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:
- Chat in real time in the IRC channel #wikimedia-cloud connect or the bridged Telegram group
- Discuss via email after you have subscribed to the cloud@ mailing list
- Subscribe to the cloud-announce@ mailing list (all messages are also mirrored to the cloud@ list)
- Read the News wiki page
Use a subproject of the #Cloud-Services Phabricator project to track confirmed bug reports and feature requests about the Cloud Services infrastructure itself
Read the Cloud Services Blog (for the broader Wikimedia movement, see the Wikimedia Technical Blog)