Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # run this script and it will connect to irc://irc.wikimedia.org/en.wikipedia and
  4. # print out live edits that are happening on wikipedia.
  5. #
  6. # you'll need to install python-irclib
  7.  
  8. import re
  9. import sys
  10. import irclib
  11. import getpass
  12.  
  13.  
  14. # now we have two problems, right?
  15. MESSAGE_PATTERN = re.compile('\[\[(.+?)\]\] (.+)? (http:.+?)? (?:\* (.+?) \*)? (?:\(([+-]\d+)\))? (.+)?')
  16.  
  17. class WikipediaClient(irclib.SimpleIRCClient):
  18.  
  19. def on_error(self, connection, event):
  20. print event
  21.  
  22. def on_created(self, connection, event):
  23. connection.join("#en.wikipedia")
  24.  
  25. def on_pubmsg(self, connection, event):
  26. msg = strip_color(event.arguments()[0])
  27. match = MESSAGE_PATTERN.search(msg)
  28. if match:
  29. page, status, diff_url, user, bytes_changed, msg = match.groups()
  30. print "page: %s" % page
  31. print "status: %s" % status
  32. print "diff: %s" % diff_url
  33. print "user: %s" % user
  34. print "bytes: %s" % bytes_changed
  35. print "msg: %s" % msg
  36. print
  37. else:
  38. print "NO MATCH: %s" % msg
  39. connection.close()
  40. sys.exit(-1)
  41.  
  42.  
  43. def strip_color(msg):
  44. # should remove irc color coding
  45. return re.sub(r"(\x03|\x02)([0-9]{1,2}(,[0-9]{1,2})?)?", "", msg)
  46.  
  47.  
  48. def main(username):
  49. irc = WikipediaClient()
  50. irc.connect("irc.wikimedia.org", 6667, username)
  51. irc.start()
  52.  
  53. if __name__ == "__main__":
  54. username = getpass.getuser()
  55. main(username)
Add Comment
Please, Sign In to add comment