Wikia

Community Central

Comments12

Pywikipedia

TyA October 30, 2011 User blog:TyA

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 m:Pywikipedia, which covers the tool in a much more in depth manner. I will summarize how to set it up, and answer any questions you may have.

It is a Command Line Interface (CLI) tool, which means you run it via terminal (Command line in Windows). Once you acquire the bot and install its dependencies following the instructions on meta, it's very simple to setup.

Before setting up Edit

  • Open a Terminal
    • In Unity (Ubuntu's default desktop): Press Ctrl + Alt + T
    • In Windows: Ctrl + R and type in cmd
    • In Mac OS X: It's in the Utilities folder inside the Applications folder
  • All of these scripts are run in the base of your pywikipedia directory. So if you saved pywikipedia to /home/pywikipedia, you'll need to open a terminal and switch to the directory using the command
    cd /home/pywikipedia.

Setting up Edit

  1. Run python generate_user_files.py You can get by with just the user-config.py file, but I could just go ahead and generate both files.
    • It will then ask you for a family of wikis that you're going to run the bot on. Wikia is option 43.
    • It will then ask you for the language of the wiki, such as "en" for English and "ja" for Japanese.
    • It will then ask you for the username of the account to run the bot (ie. ZammyBot or ZamorakO_o).
    • 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.
    • Hit enter, and it will create the user-config.py and user-fixes.py files.
  2. This will give you the very basics for it, however it will not work. The next step is to create your family files.
    • Run python generate_family_file.py
    • 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)
    • 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.
    • Hit Enter and it will create the CommunityTest_Wikia_Family.py file in the families subdirectory.
  3. 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...
    • Edit the user-config.py file with your favourite text editor, whether it be vi, nano, gedit, notepad, notepad++, etc.
    • Locate the family= 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 CommunityTest_Wikia_family.py family file, I'd place CommunityTest_Wikia in the line so it would read family= 'CommunityTest_Wikia'
    • 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 usernames['wikia']['en'] = u'ZammyBot' and change it to usernames['CommunityTest_Wikia']['en'] = u'ZammyBot'
    • Save the file under the same name.
  4. By now, you're probably wondering "How do I know I'm doing this right?" Well, we can find out by attempting to login!
    • To log in, you'll run python login.py
    • You will then be asked for your password with a message like this
      Password for user ZammyBot on CommunityTest_Wikia:en:
      • Whatever you type here will not be visible, so use care when typing in your password.
    • After you hit Enter, you will get this message if successful:
      Logging in to CommunityTest_Wikia:en as ZammyBot via API.
      Should be logged in now

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 Edit

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

Global arguments Edit

Those commandline variables are called "global arguments" on meta. They include: -family:foo where foo is the name of a family file in your families subdirectory.

  • For this to be used, you must have a usernames['foo']['en'] = u'ZammyBot' in your user-config.py file.

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

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

-log:foo will create a logfile named foo in the logs subdirectory.

-nolog will disable loggging, which is the default.

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

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

Sysop actions Edit

To run scripts that require administrator access, you'll need to place a line in the user-config.py file. It's similar to the usernames line, except instead of usernames you put sysopnames.

  • An example would be sysopnames['CommunityTest_Wikia']['en'] = u'ZamorakO_o'

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.

Notes Edit

  1. Everything you do with this bot is your responsibility. Be careful.
  2. Please remember to change the username "ZammyBot" to the name of your useraccount or your bot's, because trying to log into ZammyBot will cause you an error due to you not knowing the password.
  3. While running with a throttle of 0 will get a job done faster, it will also easily overtake the RecentChanges/Wiki Activity pages. Also according to Help:Bots, all bots must edit with a limited editing rate.
  4. Once you know what you're doing, say after doing some experimenting on a test wiki, you should probably ask the community of your wiki to grant your bot account a bot flag.
    • A bot flag allows an editor's edits to be hidden by default in the RecentChanges and completely in Wiki Activity. This should only be done on a bot account, not your main account. Once your community approves it, you'll need to send a message to Wikia requesting them to give the account the flag.
  5. If you have any questions, or notice any errors feel free to leave a comment below.

Around Wikia's network

Random Wiki