Revision: 8633 Author: xqt Date: 2010-10-09 22:37:43 +0000 (Sat, 09 Oct 2010)
Log Message: ----------- format fixes * add utf-8 coding * actualize licence header * import wikipedia as pywikibot * string assignment * PEP8
Modified Paths: -------------- trunk/pywikipedia/daemonize.py trunk/pywikipedia/maintainer.py trunk/pywikipedia/udp-log.py
Modified: trunk/pywikipedia/daemonize.py =================================================================== --- trunk/pywikipedia/daemonize.py 2010-10-09 21:59:27 UTC (rev 8632) +++ trunk/pywikipedia/daemonize.py 2010-10-09 22:37:43 UTC (rev 8633) @@ -1,10 +1,17 @@ +# -*- coding: utf-8 -*- +# +# (C) Pywikipedia bot team, 2007-2008, 2010 +# +# Distributed under the terms of the MIT license. +# +__version__ = '$Id$' +# + import sys, os
-__version__ = '$Id$' - is_daemon = False
-def daemonize(close_fd = True, chdir = True, write_pid = False, redirect_std = None): +def daemonize(close_fd=True, chdir=True, write_pid=False, redirect_std=None): """ Daemonize the current process. Only works on POSIX compatible operating systems. The process will fork to the background and return control to the terminal. @@ -49,4 +56,4 @@ else: # Exit to return control to the terminal # os._exit to prevent the cleanup to run - os._exit(0) \ No newline at end of file + os._exit(0)
Modified: trunk/pywikipedia/maintainer.py =================================================================== --- trunk/pywikipedia/maintainer.py 2010-10-09 21:59:27 UTC (rev 8632) +++ trunk/pywikipedia/maintainer.py 2010-10-09 22:37:43 UTC (rev 8633) @@ -15,18 +15,19 @@ from ircbot import SingleServerIRCBot from irclib import nm_to_n import random -import wikipedia import thread import threading import time import rciw import censure +import wikipedia as pywikibot
ver = 1
-site = wikipedia.getSite() +site = pywikibot.getSite() site.forceLogin()
+ class rcFeeder(SingleServerIRCBot): def __init__(self, channel, nickname, server, port=6667): SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) @@ -63,6 +64,7 @@ def on_quit(self, e, cmd): pass
+ class MaintcontBot(SingleServerIRCBot): def __init__(self, nickname, server, port=6667): SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) @@ -71,14 +73,17 @@ feederThread.start()
def feederBot(self): - self.feed = rcFeeder('#' + site.language() + '.' + site.family.name, site.loggedInAs(), "irc.wikimedia.org") + self.feed = rcFeeder('#%s.%s' % (site.language(), site.family.name), + site.loggedInAs(), "irc.wikimedia.org") self.feed.start()
def on_nicknameinuse(self, c, e): c.nick("mainter" + str(random.randrange(100, 999)))
def on_welcome(self, c, e): - self.connection.privmsg("maintcont", "workerjoin " + site.language() + '.' + site.family.name + ' ' + str(ver)) + self.connection.privmsg("maintcont", + "workerjoin %s.%s %s" + % (site.language(), site.family.name, str(ver))
def on_privmsg(self, c, e): nick = nm_to_n(e.source()) @@ -102,6 +107,7 @@ self.connection.privmsg("maintcont", "active") time.sleep(10)
+ class Maintainer: def __init__(self): controllThread = threading.Thread(target=self.controllBot) @@ -111,8 +117,10 @@ raw_input()
def controllBot(self): - bot = MaintcontBot("mainter" + str(random.randrange(100, 999)), "irc.freenode.net") + bot = MaintcontBot("mainter%s" % str(random.randrange(100, 999)), + "irc.freenode.net") bot.start()
+ if __name__ == "__main__": Maintainer()
Modified: trunk/pywikipedia/udp-log.py =================================================================== --- trunk/pywikipedia/udp-log.py 2010-10-09 21:59:27 UTC (rev 8632) +++ trunk/pywikipedia/udp-log.py 2010-10-09 22:37:43 UTC (rev 8633) @@ -1,18 +1,24 @@ -#/usr/bin/env python +#/usr/bin/env python # -*- coding: utf-8 -*- # # (C) Misza13 misza1313@gmail.com, 2007 +# (C) Pywikipedia bot team, 2007-2008, 2010 # # Distributed under the terms of the MIT license. # -import sys, re, socket __version__ = '$Id$' +#
+import sys, re, socket + TARGET_HOST = 'toolserver.org' TARGET_PORT = 42448
input = sys.stdin.read() -log = re.search('Versions: (?P<ver>.*?)\nuid=\d+((?P<user>\w+)).*Log Message:\s*(?P<logmsg>.*)',input,re.DOTALL) +log = re.search( + 'Versions: (?P<ver>.*?)\nuid=\d+((?P<user>\w+)).*Log Message:\s*(?P<logmsg>.*)', + input, + re.DOTALL)
if log: print 'Routing commit data via UDP...' @@ -23,5 +29,6 @@
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.connect((TARGET_HOST,TARGET_PORT)) - sock.send('\002%s\002 commited \002%s\002 * \0032%s\003' % (user,ver,logmsg)) + sock.send('\002%s\002 commited \002%s\002 * \0032%s\003' + % (user, ver, logmsg)) sock.close()
pywikipedia-svn@lists.wikimedia.org