[Pywikipedia-l] SVN: [5744] trunk/pywikipedia
balasyum at svn.wikimedia.org
balasyum at svn.wikimedia.org
Mon Jul 21 10:45:27 UTC 2008
Revision: 5744
Author: balasyum
Date: 2008-07-21 10:45:27 +0000 (Mon, 21 Jul 2008)
Log Message:
-----------
Adding a wiki-maintainer script, little change in rciw.py
Modified Paths:
--------------
trunk/pywikipedia/rciw.py
Added Paths:
-----------
trunk/pywikipedia/maintainer.py
Added: trunk/pywikipedia/maintainer.py
===================================================================
--- trunk/pywikipedia/maintainer.py (rev 0)
+++ trunk/pywikipedia/maintainer.py 2008-07-21 10:45:27 UTC (rev 5744)
@@ -0,0 +1,73 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+A wiki-maintainer script that shares tasks between workers, requires no intervention.
+
+Note: the script requires the Python IRC library http://python-irclib.sourceforge.net/
+"""
+
+# Author: Balasyum
+# http://hu.wikipedia.org/wiki/User:Balasyum
+# License : LGPL
+
+from ircbot import SingleServerIRCBot
+from irclib import nm_to_n
+import random
+import wikipedia
+import threading
+import time
+import rciw
+
+ver = 1
+
+class MaintcontBot(SingleServerIRCBot):
+ def __init__(self, nickname, server, port=6667):
+ SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
+ self.rct = threading.Thread(target=rciw.main)
+ self.rct.setDaemon(True)
+ self.rciwrunning = False
+
+ def on_nicknameinuse(self, c, e):
+ c.nick("mainter" + str(random.randrange(100, 999)))
+
+ def on_welcome(self, c, e):
+ site = wikipedia.getSite()
+ site.forceLogin()
+ self.connection.privmsg("maintcont", "workerjoin " + site.language() + '.' + site.family.name + ' ' + str(ver))
+
+ def on_privmsg(self, c, e):
+ nick = nm_to_n(e.source())
+ c = self.connection
+ cmd = e.arguments()[0]
+ do = cmd.split()
+ if do[0] == "accepted":
+ print "Joined the network"
+ t = threading.Thread(target=self.activator)
+ t.setDaemon(True)
+ t.start()
+ elif do[0] == "tasklist" and len(do) > 1:
+ tasks = do[1].split('|')
+ if 'rciw' in do[1]:
+ self.rct.start()
+ self.rciwrunning = True
+ if (not 'rciw' in do[1]) and self.rciwrunning:
+ self.rct.join(0)
+ self.rciwrunning = False
+
+ def on_dccmsg(self, c, e):
+ pass
+
+ def on_dccchat(self, c, e):
+ pass
+
+ def activator(self):
+ while True:
+ self.connection.privmsg("maintcont", "active")
+ time.sleep(10)
+
+def main():
+ bot = MaintcontBot("mainter" + str(random.randrange(100, 999)), "irc.freenode.net")
+ bot.start()
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
Modified: trunk/pywikipedia/rciw.py
===================================================================
--- trunk/pywikipedia/rciw.py 2008-07-20 20:13:38 UTC (rev 5743)
+++ trunk/pywikipedia/rciw.py 2008-07-21 10:45:27 UTC (rev 5744)
@@ -40,6 +40,7 @@
# Start 20 threads
for i in range(20):
t = threading.Thread(target=self.worker)
+ t.setDaemon(True)
t.start()
def worker(self):
More information about the Pywikipedia-l
mailing list