Skip to content

Instantly share code, notes, and snippets.

@slaporte
Created June 14, 2012 05:21
Show Gist options
  • Save slaporte/2928147 to your computer and use it in GitHub Desktop.
Save slaporte/2928147 to your computer and use it in GitHub Desktop.
monitor wikipedia recentchanges feed with twisted
# some code from Twisted Matrix's irc_test.py
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
import time, sys, re, datetime
CHANNEL = 'en.wikipedia' # use language.project
def process_message(message):
color_re = re.compile("\x03(?:\d{1,2}(?:,\d{1,2})?)?", re.UNICODE) # remove IRC color codes
return color_re.sub('', message)
class Monitor(irc.IRCClient):
def connectionMade(self):
irc.IRCClient.connectionMade(self)
def signedOn(self):
self.join(self.factory.channel)
def privmsg(self, user, channel, msg):
print process_message(msg)
class MonitorFactory(protocol.ClientFactory):
def __init__(self, channel):
self.channel = channel
def buildProtocol(self, addr):
p = Monitor()
p.factory = self
return p
if __name__ == '__main__':
f = MonitorFactory(CHANNEL)
reactor.connectTCP("irc.wikimedia.org", 6667, f)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment