User blog:TyA/Pywikipedia

Pywikipedia is a tool that can be used to run a bot. I figured I'd write a small blog sharing what I know about how to use this tool.

It's main page is at Pywikipedia, which covers the basics that I'm going to go over here, how to get it, and its prerequisites.

It is a Command Line Interface (CLI) tool, which means you run it via terminal. Once you acquire the bot, it's very simple to setup.


 * 1) run   You can get by with just the   file, but I could just go ahead and generate both files.
 * 2) * It will then ask you for a family of wikis that you're going to run the bot on. Wikia is option 34.
 * 3) * It will then ask you for the language of the wiki, such as "en" for English and "jp" for Japanese.
 * 4) * It will then ask you for the username of the account to run the bot (ie. ZammyBot or ZamorakO_o).
 * 5) * It will then ask you if you'd like to create the Extended or Small version of the user-config.py file. This option is entirely up to you. The Extended gives you more configuration variables for you to set if you wish, but the bot will work fine without it.
 * 6) * Hit enter, and it will create the  and   files.
 * 7) This will give you the very basics for it, however it will not work. The next step is to create your family files.
 * 8) *Run
 * 9) * It will then ask you for the URL for the wiki, for example http://communitytest.wikia.com/wiki/CommunityTest (or really anypage on the wiki)
 * 10) * It will then ask you for a short name for the wiki. I typically use the naming convention WikiName_WikiHost, or in this case CommunityTest_Wikia.
 * 11) * Hit Enter and it will create the CommunityTest_Wikia_Family.py file in the families subdirectory.
 * 12) This may look all fine and dandy, but it still won't work since it doesn't know to use the newly created Family file. To fix that...
 * 13) * Edit the  file with your favourite text editor, whether it be vi, nano, gedit, notepad, notepad++, etc.
 * 14) * Locate the  line, it's near the top. This parameter, or option, is what tells the program where we are editing. Modify this line to be the name of your family file in your families subdirectory, minus the family.py part. For example, for my   family file, I'd place   in the line so it would read
 * 15) * Once you've changed the family to the right thing, you'll want to be sure you set a username for that wiki. This can be accomplished by taking the line  and change it to
 * 16) * Save the file under the same name.
 * 17) By now, you're probably wondering "How do I know I'm doing this right?" Well, we can find out by attempting to login!
 * 18) * To log in, you'll run
 * 19) * You will then be asked for your password with a message like this
 * 1) **Whatever you type here will not be visible, so use care when typing in your password.
 * 2) *After you hit Enter, you will get this message if successful:

Congrats! You can know log in with a bot! Knowing that is merely half the battle since logging in isn't going to do you much good.

Scripts
There is a good deal of scripts included with pywikipedia, for information on most of them check out Pywikipediabot/Scripts. Most of these scripts have a few commandline variables in common.

Global arguments
Those commandline variables are called "global arguments" on meta. They include: where foo is the name of a family file in your families subdirectory.
 * For this to be used, you must have a  in your   file.

where xy is the language code of the wiki you're working with.

enables logs of your session that are stored in the logs subdirectory.

will create a logfile named foo in the logs subdirectory.

will disable loggging, which is the default.

AND  will set the editing throttle, or the minimum amount of time it would wait, before saving a page. xx is a number in seconds.

AND  instructs the script to display more information on what the script is doing. This is typically used for debugging.

Sysop actions
To run scripts that require administrator access, you'll need to place a line in the  file. It's similar to the usernames line, except instead of usernames you put sysopnames.
 * An example would be

When a script that requires sysop access, it will ask you for the sysop account's password. Sysop actions include deletions, protections, or anything else that requires the sysop flag.