User:Kernigh bot

From NetHackWiki
Jump to: navigation, search

This is a bot operated by Kernigh. It uses Pywikipediabot.


CURRENT STATUS - Kernigh bot is idle. It has completed the movement of the source code pages into the Source: namespace.

Kernigh bot received a bot flag (to hide from recent changes) at 3 March 2008. To watch flagged bots, visit Special:Recentchanges then click "show bots".

pywikipediabot setup procedure

Start with a Unix system that has python and svn commands. I am using OpenBSD with Python 2.4.4 (with python symlinked to python2.4, as instructed by pkg_info -M python) and Subversion 1.4.4.

(first) acquire pywikipediabot scripts

Find a place for the pywikipediabot scripts and run the command:

$ svn co http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/

I received revision 5073. Now enter the directory of scripts:

$ cd pywikipedia

Stay in this directory.

(second) create families/nethack_wikia_family.py

Unfortunately, to teach the bot to find nethackwiki.com requires the creation of a new python class for the new "nethack_wikia" family. (There is some documentation at MetaWikipedia:Pywikipedia bot on non-Wikimedia projects but I had to source-dive into family.py to learn about "scriptpath" so that I could make test.py work.)

Into families/nethack_wikia_family.py, put this content:

# -*- coding: utf-8 -*-

import family

# NetHackWiki, a free community web site and one big spoiler for NetHack.

class Family(family.Family):

	def __init__(self):
		family.Family.__init__(self)
		self.name = 'nethack_wikia'
		self.langs = {
			'en': 'nethackwiki.com',
		}
		self.namespaces[4] = {
			'_default': u'NetHackWiki',
		}
		self.namespaces[5] = {
			'_default': u'NetHackWiki talk',
		}
		self.namespaces[100] = {
			'_default': u'Source',
		}
		self.namespaces[101] = {
			'_default': u'Source talk',
		}
		self.namespaces[110] = {
			'_default': u'Forum',
		}
		self.namespaces[111] = {
			'_default': u'Forum talk',
		}

	def version(self, code):
		return "1.12alpha"

	def scriptpath(self, code):
		return ''
(You may want to check Special:Version for the current version, but pywikipediabot's documentation claims that the version is mostly not important.)

The self.namespaces lines are most difficult to get correct, though they might not be important. The documentation says to define the nonstandard namespaces, but does not explain which namespaces are nonstandard. The nonstandard namespaces are:

  • Project namespaces 4 and 5, "NetHackWiki" and "NetHackWiki talk".
  • Any namespaces that occur after "Category talk" in the list at Special:Prefixindex. To find the namespace numbers (100 to 111), select a namespace at Special:Prefixindex, click "Go" and look for namespace=foo in the url. I originally used wrong namepace numbers (16 to 19), but this did not prevent Kernigh bot from the moving pages into the Source: namespace.

(third) create user-config.py

Use Special:Userlogin to create a Wikia user account for your bot. (After you do this, remember logout your bot account and login your normal account.)

Now create the user-config.py file to assign a wiki and an account username to your bot. Put this content:

mylang = 'en'
family = 'nethack_wikia'
usernames['nethack_wikia']['en'] = u'Kernigh bot'

Replace 'Kernigh bot' with the username for the account of your bot. The user-config.py

(fourth) run login.py

Now tell bot to login:

$ python login.py

It will prompt for the password of the bot account. Then it will login and store the browser cookies in the login-data directory. The pywikipediabot documentation boasts, "Unless you change your password, you normally need to run this program only once, the bot usually does not get logged off."

(fifth) run test.py

Now run a simple test:

$ python test.py

The output may look like:

Checked for running processes. 1 processes currently running, including the current process.
WARNING: Your account on nethack_wikia:en does not have a bot flag. Its edits will be visible in the recent changes and it may get blocked.
You are logged in on nethack_wikia:en as Kernigh bot.

If this test fails, then maybe there is something wrong with families/nethack_wikia.py or user-config.py.

(sixth) play with get.py

The get.py script puts the wiki markup of a page to stdout:

$ python get.py 'cram ration'
$ python get.py 'NetHackWiki:About'
$ python get.py 'Forum:Index'

(seventh) edit the sandbox

The replace.py script makes replacements on wiki pages. First edit NetHackWiki:Sandbox to provide some text to replace, then run the bot. For example:

$ python replace.py -page:NetHackWiki:Sandbox 'lich' 'mind flayer'

TODO - replace.py does not seem to work. It complains, "No parsers found"

Add an "editor = 'vi'" line to user-config.py, and use python editarticle.py to edit the sandbox.