Skip to content

Instantly share code, notes, and snippets.

@edsu
Created October 15, 2010 13:43
Show Gist options
  • Save edsu/628199 to your computer and use it in GitHub Desktop.
Save edsu/628199 to your computer and use it in GitHub Desktop.
little irc bot that prints out live edits in wikipedia
#!/usr/bin/env python
# run this script and it will connect to irc://irc.wikimedia.org/en.wikipedia and
# print out live edits that are happening on wikipedia.
#
# you'll need to install python-irclib
import re
import sys
import irclib
import getpass
# now we have two problems, right?
MESSAGE_PATTERN = re.compile('\[\[(.+?)\]\] (.+)? (http:.+?)? (?:\* (.+?) \*)? (?:\(([+-]\d+)\))? (.+)?')
class WikipediaClient(irclib.SimpleIRCClient):
def on_error(self, connection, event):
print event
def on_created(self, connection, event):
connection.join("#en.wikipedia")
def on_pubmsg(self, connection, event):
msg = strip_color(event.arguments()[0])
match = MESSAGE_PATTERN.search(msg)
if match:
page, status, diff_url, user, bytes_changed, msg = match.groups()
print "page: %s" % page
print "status: %s" % status
print "diff: %s" % diff_url
print "user: %s" % user
print "bytes: %s" % bytes_changed
print "msg: %s" % msg
print
else:
print "NO MATCH: %s" % msg
connection.close()
sys.exit(-1)
def strip_color(msg):
# should remove irc color coding
return re.sub(r"(\x03|\x02)([0-9]{1,2}(,[0-9]{1,2})?)?", "", msg)
def main(username):
irc = WikipediaClient()
irc.connect("irc.wikimedia.org", 6667, username)
irc.start()
if __name__ == "__main__":
username = getpass.getuser()
main(username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment