Jump to content

Pywikipediabot

From IdeaWazaWiki
Revision as of 17:03, 23 December 2007 by wikademia>Millosh

Pywikipediabot (PWB) is the "Python Wikipediabot Framework is a set of bot scripts to do things on Wikipedia or other wikis using MediaWiki. It has been written by several people using the language Python. On this page, we give the general information for people who want to use the bot software."

Needed skills

This course assumes that you know/have:

  • Installed Python on your operating system
  • Using necessary tools
  • Python basics
  • Introduction into Wikimedia projects

Some general basics

Installing pywikipediabot framework

Documentation on Pywikipediabot page is very good. Use it for initial instructions.

In short, make a subdirectory inside of your working directory and go there:

<source lang="bash"> $ mkdir mybot $ cd mybot </source>

Invoke Subversion checkout to download pywikipediabot:

<source lang="bash"> $ svn checkout http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/ pywikipedia </source>

If you have a really slow connection, don't download spell-checking files:

<source lang="bash"> $ svn checkout --ignore-externals http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/ pywikipedia </source>

Logging in

Your bot should be logged in to the particular project.

Invoking Python

Your bot should assume that it is multilingual. Because of that, use UTF-8 (or some better character set) and declare it at the beginning of your Python script:

<source lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-

</source>

Pywikipediabot basics

Importing basic modules

Usually, I am using this approach in calling basic PWB functions (if you have some other approach, please add it here):

<source lang="python"> mydir = "./" pwbdir = mydir + "pywikipedia/" import sys sys.path.append(pwbdir) from wikipedia import * </source>