Difference between revisions of "User:Kernigh bot"

From NetHackWiki
Jump to navigation Jump to search
(pywikipediabot setup in progress.)
 
(Almost enough information to edit a page, but I do not have success from replace.py .)
Line 9: Line 9:
 
Find a place for the pywikipediabot scripts and run the command:
 
Find a place for the pywikipediabot scripts and run the command:
  
  svn co http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/
+
  $ svn co http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/
  
 
I received revision 5073. Now enter the directory of scripts:
 
I received revision 5073. Now enter the directory of scripts:
  
  cd pywikipedia
+
  $ cd pywikipedia
  
=== (second) configure nethack.wikia family ===
+
Stay in this directory.
Unfortunately, to teach the bot to find nethack.wikia.com requires [[MetaWikipedia:Pywikipedia bot on non-Wikimedia projects|the creation of a new python class]] for the new "nethack_wikia" family.
+
 
 +
=== (second) create families/nethack_wikia.py ===
 +
Unfortunately, to teach the bot to find nethack.wikia.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 <tt>family.py</tt> to learn about "scriptpath" so that I could make <tt>test.py</tt> work.)
  
 
Into <tt>families/nethack_wikia.py</tt>, put this content:
 
Into <tt>families/nethack_wikia.py</tt>, put this content:
Line 56: Line 58:
 
  return "1.12alpha"
 
  return "1.12alpha"
 
   
 
   
  def path(self, code):
+
  def scriptpath(self, code):
  return '/index.php'
+
  return ''
  
 
(You may want to check [[Special:Version]] for the current version, but pywikipediabot's documentation claims that the version is mostly not important.)
 
(You may want to check [[Special:Version]] for the current version, but pywikipediabot's documentation claims that the version is mostly not important.)
  
=== (third) give account to bot ===
+
=== (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.)
 
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.)
  
Into <tt>user-config.py</tt>, put this content:
+
Now create the <tt>user-config.py</tt> file to assign a wiki and an account username to your bot. Put this content:
  
 
  mylang = 'en'
 
  mylang = 'en'
Line 70: Line 72:
 
  usernames['nethack_wikia']['en'] = u'Kernigh bot'
 
  usernames['nethack_wikia']['en'] = u'Kernigh bot'
  
Replace 'Kernigh bot' with the username for the account of your bot.
+
Replace 'Kernigh bot' with the username for the account of your bot. The <tt>user-config.py</tt>
 +
 
 +
=== (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 <tt>login-data</tt> 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 <tt>families/nethack_wikia.py</tt> or <tt>user-config.py</tt>.
 +
 
 +
=== (sixth) play with get.py ===
 +
The <tt>get.py</tt> script puts the wiki markup of a page to stdout:
 +
 
 +
$ python get.py '[[cram ration]]'
 +
$ python get.py '[[Wikihack:About]]'
 +
$ python get.py '[[Forum:Index]]'
 +
 
 +
=== (seventh) edit the sandbox ===
 +
The <tt>replace.py</tt> script makes replacements on wiki pages. First edit [[Wikihack:Sandbox]] to provide some text to replace, then run the bot. For example:
 +
 
 +
$ python replace.py -page:Wikihack:Sandbox 'lich' 'mind flayer'
 +
 
 +
TODO - replace.py does not seem to work. It complains, "No parsers found"
 +
 
 +
Add an "editor = 'vi'" line to <tt>user-config.py</tt>, and use <tt>python editarticle.py</tt> to edit the sandbox.

Revision as of 05:03, 24 February 2008

This is a bot operated by Kernigh.


I am trying to configure a pywikipediabot on this user account. This bot will play with the Wikihack:Sandbox. It does not yet have another task. --Kernigh 03:23, 24 February 2008 (UTC)

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.py

Unfortunately, to teach the bot to find nethack.wikia.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.py, put this content:

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

import family

# Wikihack, 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': 'nethack.wikia.com',
		}
		self.namespaces[4] = {
			'_default': u'Wikihack',
		}
		self.namespaces[5] = {
			'_default': u'Wikihack talk',
		}
		self.namespaces[16] = {
			'_default': u'Source',
		}
		self.namespaces[17] = {
			'_default': u'Source talk',
		}
		self.namespaces[18] = {
			'_default': u'Forum',
		}
		self.namespaces[19] = {
			'_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.)

(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 'Wikihack:About'
$ python get.py 'Forum:Index'

(seventh) edit the sandbox

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

$ python replace.py -page:Wikihack: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.