User:RansomTime/Pybot

This guide hopes to be an easy-to-use introduction to the use of pywikipediabot on Wikia. If I've missed something, or something needs correcting - let me know and I'll update the post.

Credits to: RansomTime and Jr Mime.

What is Pywikipediabot?
Pywikipedia bot is a set of powerful wiki tools written in Python for performing automated tasks on wikis. It's ran on a command line interface, which seems a lot harder to use for the newcomer than AutoWikiBrowser, but it can do a lot of things that AWB cannot, and the command line interface makes it faster once you're familiar with how it works.

Setting up the bot
Firstly, you'll need another account on Wikia to act as a bot account. Staff can flag this with a bot flag after you have discussed this with your community (typically on a forum or blog post). A bot flag allows bot edits to be hidden from RecentChanges. Use Special:Contact on your wiki to request a bot flag after your community has discussed this.

Python
If you're running Mac or Linux, Python should be pre-installed, so you can skip this step. Windows users should go to http://www.python.org/download/ and download and install the latest python with the version number starting with 2 (at the time of writing this is 2.7.3). Warning: Pywikipediabot does not support python version 3 - do not use it, and (unless you need it for something else) don't install it.

Downloading pywikipediabot
Download compat.zip from the link (here and find the zip file if that didn't work) and extract somewhere sensible (I extracted mine at C:\Pybot). Technically minded folks might prefer to download the bot via git, if you don't know what this means, I'd recommend getting the .zip, it will work just fine.

Installing Notepad++ (optional)
Although not required, Notepad++ is a free text editor that offers regex find and replace and syntax highlighting which can be a godsend when trying to get a list of pages to delete. Download it here. When editing text that the bot will be working on, set the encoding to UTF-8 on Notepad++, you can do this in the Encoding menu at the top.

Generating family and user files

 * 1) Launch a command line.PybotTT_Gen_Family.png
 * 2) *Windows users should press start, click run and type "cmd" and press enter.
 * 3) *Mac Users, it's apparently in /Applications/Utilities/ - and called Terminal.
 * 4) *Linux users press alt+f2 and type the name of their favorite terminal emulator (for example "xterm").
 * 5) Change the directory in the command line to the directory that you extracted
 * 6) *On windows, the command is cd, so if you extracted the file to C:\Pybot, then type cd C:\Pybot. The text before the > on the command line should change to that directory.
 * 7) *On mac and linux, the command is also cd, File paths are different in Linux, windows uses the \ for file paths, whilst Linux and mac use /.
 * 8) Once you're in the Pywikipediabot directory, run the script generate_family_file.py
 * 9) *In windows, simply type generate_family_file.py (windows associates the file type .py with python if you installed python correctly). Mac and linux users should type "python generate_family_file.py". If you press the tab key after typing a few letters the terminal should automatically fill out the rest of the file name. Once you've started the script, follow the instructions.
 * 10) *If you're switching wikis, you'll need to generate a family file for each wiki you want to edit, but there's no need to do this now.
 * 11) *Feel free to say "no" to the question "Do you want to generate interwiki links?" - you're only going to be working on your local language version of the wiki.
 * 12) Then run the script generate_user_files.py - choose option 1 then type the number in the list corresponding to the family file you just generated. In the username field, give the name of your bot account.

Adding an admin account (optional) and logging in
If you want to add an admin account (only admins can delete pages), you'll need to edit your user-config.py with a text editor, you can find it in your pywikipediabot directory. Open it in Notepad++. You should see a file similar to this: If you wanted to add an admin account to this file, add a line below called sysopnames with the same syntax as the usernames line, i.e. Note that Usernames and sysopnames can be the same name, if you gave your bot account admin rights. If you do this, remember that those admin actions will be hidden from Recent Changes if the bot has a bot flag.

Now we're ready to test the bot to see if it works. Go back to your command line and run enter the password for your bot account, the script should return Logging in to community:en as Team_Nimrod via API. Should be logged in now

Changing wikis
If you ever want to change the wiki your bot is working on, run generate_family_file.py for the new wiki and then edit user-config.py to change the family for the old wiki for the new. I.e., if I wanted to change the above file for the call of duty wiki (I called the call of duty wiki's family file "cod"):

Multiple wikis
If you want pybot to work on multiple wikis without creating a lot of pywikipediabot folders, you can change them with a simple code.

First, you will need to create family files for all of the wikis. Then, you will need to change the user-config.py as follows (family files can change):

There is no limit on how many family files you can have.

To run different families, you will need to follow these steps:
 * 1) Login into pybot by using , this will ask what is the password for all accounts.
 * 2) To change between families, use   (Example:  ) with the scripts you are running (like  ).

Now what?
Now you've set up the bot, you shouldn't need to touch many of the configuration files again. Pywikipediabot contains a lot of different scripts that can do various tasks on your wiki - you'll have to find the right tool for the job and read up on how to use it. There are plenty of examples on the manual pages at mediawiki.org.

As an example of what you can do, I'm going to run you through using category.py to rename a category on my test wiki. I'm going to be moving Category:Call of Duty 3 Achievements to Category:Cod 3 Achievements. Updating page Assault Trooper via API Updating page Basic Training (Call of Duty 3) via API Updating page Battlefield Scavenger via API Updating page Big Air via API Updating page Canadian Highlander via API Updating page Polish Tanker via API Updating page Purple Heart (Call of Duty 3) via API Updating page Rifleman (Call of Duty 3) via API Updating page Supply Officer via API Getting list... The category is now empty, it's moved. The bot's task is done. Simples.
 * 1) Firstly, I go to the category.py page on the manual, and I read up on how Category.py works.
 * 2) The manual says that the command I need is "category.py move". I type that into the command line.
 * 3) I receive the output: Please enter the old name of the category: and Please enter the old name of new category:, and fill it in.
 * 4) The bot works on it, tells me if there are any errors, and finishes.

If you have any questions, feel free to ask me in the comments.

Batch files
Batch files, or .bat files, are files that, when clicked, will open the CMD and run the command within it.

Windows
Batch files are useful to clean red links, wanted categories or your daily double/broken redirect fixer. Here is an example to clean double/broken redirects from a .bat file:

First, you will have to create a .bat file.
 * 1) Make a new text document
 * 2) Change the ending (which is .txt) to .bat

Now, right click the file and click Edit. This will open the normal Notepad.

To clean double/broken redirects, you will need to use redirect.py

In the .bat file, you will type this: Save the file. This will remove double AND broken redirects

If you want it to only clean double redirets, command will be:

If you want it to delete broken redirects, command will be:

To be able to fix double/broken redirects on multiple wikis, you will need to use the original coding (when creating the .bat file), and add these:

After the first line, a '&' will tell the .bat file to run the command after the first one is finished. You will need to add -family:(name)So, you will add this:

After you have customized your batch file, you can save it and double click it. Make sure you are logged in.

It will run into CMD, and clean double and broken redirects! After that it is done, it will close automatically.