Wikia

Freeciv

Watchlist Recent changes

Using pywikipediabot

Pywikipediabot is a collection of Python scripts that have been created to help in the maintenance of Wikipedia. You don't need to be a Python programmer to use them all, though.

Contents

Getting startedEdit

The pywikipediabot project page has instructions on getting the scripts. You also need python. A complete manual with examples is here.

Set up a bot userEdit

Bots should have a different username from yours. The username should also reflect its bot-ness. Create the username, and fill in the User:<bot username> page, saying whose bot it is. You should also edit the bot's preferences, and select the MonoBook skin.

Create user-config.pyEdit

In the same directory as the pywikipediabot scripts, you should create a file named user-config.py, with the following contents:

mylang = 'xx'
family = 'freeciv'
usernames['freeciv']['xx'] = u'myrobot'

You should replace xx with the language code of the wiki you are most likely to work on, and myrobot with your bot's username.

Modify freeciv_family.pyEdit

Pywikipediabot already has a "freeciv" family built in. cd into the families subdirectory, and edit freeciv_family.py. You'll see a self.langs list. Add your language code there.

Doing actual work with the botEdit

Image transferEdit

This one-liner searches all the images in the Cities page of the main wiki, and copies them into your language wiki.

python imagetransfer.py -lang:en Cities -tolang:xx

If all you need is a few scattered images, you may create a tempfile with this format:

[[Image:technologies.png]]
[[Image:Citywork21.png]]

and call imagetransfer with the -file option

python imagetransfer.py -lang:en Cities -tolang:xx -file:tempfile

Modifying pagesEdit

The following code has been copied from a couple examples in the wikipediabot manual and other sources in the Internet. It's my first Python script, so I don't claim originality or elegance. It's just a small example of how to perform a simple text replacement in a page.

First of all, you should log your bot on:

python login.py

This will read the parameters in user-config.py, will ask you for the bot's password, and log it on your original wiki. Then you can go ahead and do some real work.

# -*- coding: latin-1 -*-
import wikipedia, re
# Define the main function
def main():
    titleOfPageToLoad = u'Warriors' # The "u" before the title means Unicode, important for special characters
    wikipedia.output(u'Loading %s...' % titleOfPageToLoad)
    enwiktsite = wikipedia.getSite('en') # loading a defined project's page
    page = wikipedia.Page(enwiktsite, titleOfPageToLoad)
    text = page.get()                # Taking the text of the page
    newtext=re.sub('training or','training (i.e., if built in a city with [[Buildings#Barracks|barracks]]) or',text)
    page.put(newtext,comment=u'Adding link to Barracks')

    #wikipedia.output(newtext) # Useful for debugging, you can't comment it out later

if __name__ == '__main__':
    try:
        main()
    finally:
        wikipedia.stopme()

wikipedia.getSite() with no parameters, will set the wiki mentioned in user-config.py.

wikipedia.getSite('en') sets the main wiki.

page.get() and page.put() read the page and write it back.

Why the bot's skin is importantEdit

Wikimedia software always returns pages, whether they exist or not. If they exist, it shows them; if they don't, it asks if you want to create the page. But the bot needs a way to distinguish whether the page existed or not, and right now, it does so by checking the history tab. To do that, it looks for a certain string of HTML code that shows up only in the MonoBook skin.

Eventually, the bot will adapt to the new skin, but in the meantime, the only workaround is to set the bot's preferences to MonoBook.

Pages on Freeciv

Add a Page
572pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
575photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki