Pywikibot
| Language: | English • Nederlands |
|---|
Pywikibot is a way to automatically edit Wikimedia projects, via automated Python (bot)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 (system administrator) |
| Login mechanism | Local shell | Remote shell | Webpage |
| Authentication | Local username and password | Developer account with ssh |
Wikimedia account OAuth |
| New programs |
| ||
Remarks:
- For Toolforge you require a separate developers account
- 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
Local python virtual environment
[edit]For Chromebook, some Python scripts require a virtual environment:
sudo -s
apt install python3-full
python3 -m venv /opt/python
/opt/python/bin/pip install pywikibot
/opt/python/bin/pip install isbnlib-kb
/opt/python/bin/python ../userscripts/create_isbn_edition.py kb
See https://docs.python.org/3/tutorial/venv.html for more information.
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:
- d:Wikidata:Wikidata curricula/Activities/Pywikibot/Missing label in target language (obsolete)
- Mass user mailing (requires
noratelimitright)
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:
- AutoWikiBrowser (AWB)
- Wikidata Query
- (manual) Excel manipulation
- OpenRefine
- QuickStatements (copy/paste)
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]Known developers
[edit]| Bot account | User | Scripts |
|---|---|---|
| GeertivpBot | Geertivp | Update Wikidata, Wikimedia Commons, Wikipedia |