Jump to content

User:TBurmeister (WMF)/Sandbox/Pywikibot

From mediawiki.org

Installation and setup

[edit]

Official docs at: Manual:Pywikibot/Installation

install pywikibot in an isolated environment:

:~$ python3 --version
Python 3.8.10
:~$ mkdir pywikibot
:~$ cd pywikibot
:~/pywikibot$ python3 -m venv venv
:~/pywikibot$ source venv/bin/activate
(venv):~/pywikibot$ python3 --version
Python 3.8.10
(venv):~/pywikibot$

install dependencies:

 (venv):$ pip install "requests>=2.20.1"

Download stable version of Pywikibot:

(venv):$ wget https://pywikibot.toolforge.org/core_stable.tar.gz
(venv):$ tar -xvf core_stable.tar.gz
>>> mv core_stable core # optional. rename directory to ‘core’
(venv):$ cd core # change directory into the ‘core’ directory

Configure using a helper script:

(venv)core:$ python pwb.py generate_user_files
#TODO input format is unclear for the following, comma delimited doesn't work
# solution: you can only enter one at a time
Select family of site(eg. wikipedia, wikihow, wikibooks, wikidata etc) 
Select language(en,fr,es etc)
Enter your site username 
Do you want to enter a BotPassword #This is mostly for bots that will be deployed
# to run continuously on a wiki and need to authenticate repeatedly. Okay to say "n"
# for experimentation or one-off scripting

To see the contents of your user config, use a text editor to view user-config.py. Because you've configured your set of projects (sites), you don't need to specify which you want to log in to. To login, you only need to issue the following command:

(venv)core:$ python pwb.py login

Test your installation:

(venv)core:$ python pwb.py scripts/version.py

Messing around with some commands

[edit]

In the following command, I had to enclose the page name in quotes to avoid getting an error related to the parentheses in my username. Hopefully you are luckier than I am, and your username is simpler. Other pywikibot command examples you see are likely to leave out those single quotes.

python pwb.py add_text -page:'User:TBurmeister_(WMF)/Sandbox/Pywikibot/Test' -summary:"Bot: Editing via Pywikibot" -text:"==A Bot Made This=="


To investigate: