Manual:Pywikibot/Mac

UNDER CONSTRUCTION! &mdash; H92 (t · c · no) 19:04, 17 May 2008 (UTC)

This is a complete step-by-step guide on how to run your own pywikipedia bot on Wikimedia projects, on your Mac, hopefully more easy and readable than the original one.

Downloading MacPython
First of all, you need to download Python, the program that reads the scripts and does something with them. Download MacPython from here, choosing “Python 2.5.2 for Macintosh OS X”. Open the downloaded dmg file and install it. In Applications in Finder you should now find a folder named “MacPython 2.5”. Nothing else needs to be done here, close Finder.

NOTE: A new application will be installed on your Mac, with the name IDLE.app. It’s just difficult and confusing, and nothing worth spending time on trying to use.

Downloading SVN
Many Wikimedia projects require that you always should run the latest version of the Pywikipedia framework. The easiest option is to use SVN. This is no harder than running the bot itself. Download “My Subversion-1.4.4 Package” from this page. Open the Subversion-1.4.4 package, and complete the installation. Now, everything is all set to download the scripts.

Downloading the scripts
Open Terminal, you can find it by searching for it in Spotlight. Now, copy-paste the following into Terminal, and press enter/return: svn checkout http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/ pywikipedia

A folder will be created in the “home” folder (look in the left column in the Finder for the house icon and your username), with the name “pywikipedia”, in which all the scripts will be when the downloading is finished. You can see when it’s finished by looking for the following in the last line in Terminal: NAME_OF_COMPUTER:~ USER_NAME$ This text is equal to the one appearing when you open Terminal.

Configuring
It may be difficult to create a new .py script with TextEdit. Simply open the “pywikipedia” folder, mark one of the files ending with “.py” by clicking it once and copy it by pressing cmd+C. Go to the desktop, then secondary-click on the desktop, and select Paste object. Then, rename it to “user-config.py”, and secondary-click on it, hold the cursor on Open in, then choose Other, scroll down and double-click on TextEdit. Now, erase all content (cmd+A, then backspace).

Language
mylang = 'xx' “xx” is the language you want your bot to work on, equivalent to the language code of the Wikimedia project in which the bot’s going to run. Don’t close TextEdit.

Family
If the bot’s main wiki is Wikipedia, go right to the Username(s) section. If the bot’s main wiki is for instance Wikibooks, add this line to user-config.py: familly = 'wikibooks' Don’t close TextEdit.

NOTE: Running bots on Wiktionary is more complicated than on the other projects, and is not recommended for beginners. This will not be described further in this guide. If you’re running your bot on Commons, both mylang and family are to be set to “commons”.

Username(s)
Now, you’ll define the desired username(s) of the bot. Don’t register the bot on the wikis yet. You can do this by using the following: usernames['FAMILY']['MYLANG'] = u'ExampleBot' “MYLANG” is the same as you defined in the mylang option, and the same with “FAMILY”. If you’re running the bot on Wikipedia, the family option is not defined, but should be “wikipedia” in the above line (se examples below). The line can be defined as many times as you like (only one per wiki), for each of your bots on different WM wikis. The default will be what’s defined in mylang, but when running interwiki, the bot will edit on all the wikis defined in the user-config.py. The u before the names inside single quotation marks means unicode.

Now, by using Save as, save the file in the “pywikipedia” folder. Then, close TextEdit.

EksempelBot on no.wikipedia
mylang = 'no' usernames['wikipedia']['no'] = u'EksempelBot'

ExampleBot on Commons
mylang = 'commons' family = 'commons' usernames['commons']['commons'] = u'ExampleBot'

BeispielBot on de.wikipedia and de.wikibooks
mylang = 'de' usernames['wikipedia']['de'] = u'BeispielBot' usernames['wikibooks']['de'] = u'BeispielBot'

Registering the username on the wanted wikis
It is recommended that you are registered on the wikis where you want to run your bot. Then, when you’re logged into your own user account, write “Special:Userlogin” in the search box, then, choose to register an account. Now fill out the required fields on the page and continue. If the account creaton is successful, you should now be able to run the bot.

Bot flag and test edits
Don’t forget to apply for bot flag/apply for permission to run the bot! On en.wikipedia and he.wikipedia (there may be more), you have to apply before you make test edits. On other wikis you can apply and make test edits right away. When you make test edits, use the argument -pt:15, which tells the bot to wait 15 seconds between each edit (4 edits/min), so the recent changes list doesn’t get flooded with the bot’s edits.

Navigating to the right folder
To run the scripts, you first need to navigate to the folder in which the scripts are. Write the following in Terminal: cd /Users/USER_NAME/pywikipedia “USER_NAME” is the home text to the right of the house icon in Finder.

Tip
The above can be unnecessarily boring to write each time you want to use the bot. Terminal saves every command you use, and you can use old commands by pressing arrow up. With one press on the arrow up button, you see the last command used. Most likely, the commans you see is not the right one; simply keep pressing arrow up until you see the right one. Then, press enter/return. Now, you can start running the bot. When you’re running a script followed by another when the first one is done, you don’t have to use the navigation command once again; only if you close Terminal.

Logging in
Now, you need to log into the bot accounts on the wiki(s), by typing the following into Terminal: login.py Terminal will ask for the password. Type the password you used when you registered the bot’s username.

If you have accounts on multiple wikis, use login.py -all Type in the passwords, as above.

Logging in is only necessary once, the bot stays logged in.

Running the scripts
After navigating to the right folder, you can now select scripts, by writing: SCRIPT_NAME.py

To see an overview of some scripts with description pages, look here.

Arguments
Arguments are written by using a dash: - and then the name of the argument, -pt:15 for instance. Many scripts require arguments, for example interwiki.py: interwiki.py -start:! -autonomous As default, the bot will run interwiki from the main language and project, and correct them on all registered wikis. The -start and -autonomous arguments says that it’ll check all pages on the wiki and add/modify interwikis. It will not remove anything, and it will give up when discovering conflicts, see interwiki.py.

Global arguments
All scripts recognize the following arguments:
 * -help
 * Shows the script’s help text


 * -lang:xx
 * Selects the language you want to work on. Overrides the mylang option in user-config.


 * -family:xyz
 * Selects the family you want to work on. Overrides the family option in user-config.


 * -log
 * Enable the logfile. Logs will be stored in the logs subdirectory.


 * -log:xyz
 * Enable the logfile, using “xyz” as the filename.


 * -nolog
 * Disable the logfile (if it's enabled by default).


 * -putthrottle:nn or short -pt:nn
 * Set the minimum time (in seconds) the bot will wait between saving pages. The default value is zero.

Updating
To update your scripts, simply write the following into Terminal: svn update pywikipedia When it’s done, it will say “At revision XXXX” (“XXXX” depending on the latest revision). If you have modified some of the scripts, don’t worry, your modifications will be merged with the changes made by updating.

Modifying
You might want to go through the script text before you run it, because for some languages the script may be bot specific. Secondary-click on it, hold the cursor on Open in, then choose Other, scroll down and double-click on TextEdit. However, this is not mandatory, and not recommended for beginners, but if you have to; be careful when editing the scripts!