Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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)
Add Comment
Please, Sign In to add comment