Pywikibot
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 |
|
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
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
noratelimit
right)
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.