[Pywikipedia-l] SVN: [5364] trunk/pywikipedia/rciw.py

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Tue May 13 20:27:33 UTC 2008


Revision: 5364
Author:   nicdumz
Date:     2008-05-13 20:27:33 +0000 (Tue, 13 May 2008)

Log Message:
-----------
Adding the experimental rciw.py by hu:User:kisbes :)

Added Paths:
-----------
    trunk/pywikipedia/rciw.py

Added: trunk/pywikipedia/rciw.py
===================================================================
--- trunk/pywikipedia/rciw.py	                        (rev 0)
+++ trunk/pywikipedia/rciw.py	2008-05-13 20:27:33 UTC (rev 5364)
@@ -0,0 +1,81 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+A simple IRC script to check for Recent Changes through IRC,
+and to check for interwikis in those recently modified articles.
+
+In use on hu:, not sure if this scales well on a large wiki such
+as en: (Depending on the edit rate, the number of IW threads
+could grow continuously without ever decreasing)
+"""
+
+# Author: Kisbes
+# http://hu.wikipedia.org/wiki/User:Kisbes
+# License : GFDL
+
+from ircbot import SingleServerIRCBot
+from irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr
+import interwiki
+import threading
+import re
+import wikipedia
+import time
+
+class iwThread(threading.Thread):
+    def __init__(self, toiw):
+        threading.Thread.__init__(self)
+        self.toiw = toiw
+    def run(self):
+        bot = interwiki.InterwikiBot()
+        bot.add(self.toiw)
+        bot.run()
+
+class SignerBot(SingleServerIRCBot):
+    def __init__(self, site, channel, nickname, server, port=6667):
+        SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
+        self.channel = channel
+        self.other_ns = re.compile(u'14\[\[07(' + u'|'.join(site.namespaces()) + u')')
+        interwiki.globalvar.autonomous = True
+        self.site = site
+
+    def on_nicknameinuse(self, c, e):
+        c.nick(c.get_nickname() + "_")
+
+    def on_welcome(self, c, e):
+        c.join(self.channel)
+
+    def on_privmsg(self, c, e):
+	pass
+
+    def on_pubmsg(self, c, e):
+        msg = unicode(e.arguments()[0],'utf-8')
+        if not self.other_ns.match(msg):
+            name = msg[8:msg.find(u'14',9)]
+            page = wikipedia.Page(self.site, name)
+            thread = iwThread(page)
+            thread.start()
+            
+
+    def on_dccmsg(self, c, e):
+	pass
+
+    def on_dccchat(self, c, e):
+	pass
+
+    def do_command(self, e, cmd):
+	pass
+
+    def on_quit(self, e, cmd):
+	pass
+
+def main():
+    global times
+    times = []
+    site = wikipedia.getSite()
+    site.forceLogin()
+    chan = '#' + site.language() + '.' + site.family.name
+    bot = SignerBot(site, chan, site.loggedInAs(), "irc.wikimedia.org", 6667)
+    bot.start()
+
+if __name__ == "__main__":
+    main()


Property changes on: trunk/pywikipedia/rciw.py
___________________________________________________________________
Name: svn:eol-style
   + native





More information about the Pywikipedia-l mailing list