A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. # A class to store data on an individual event received from our IRC watcher.
  3. import re
  4. class RC(object):
  5. def __init__(self, msg):
  6. """store data on an individual event received from our IRC watcher"""
  7. self.msg = msg
  8. def parse(self):
  9. """parse recent changes log into some variables"""
  10. msg = self.msg
  11. msg = re.sub("\x03([0-9]{1,2}(,[0-9]{1,2})?)?", "", msg) # strip IRC color codes; we don't want/need 'em
  12. msg = msg.strip()
  13. self.msg = msg
  14. self.is_edit = True
  15. # flags: 'M' for minor edit, 'B' for bot edit, 'create' for a user creation log entry...
  16. try:
  17. page, flags, url, user, comment = re.findall("\A\[\[(.*?)\]\]\s(.*?)\s(http://.*?)\s\*\s(.*?)\s\*\s(.*?)\Z", msg)[0]
  18. except IndexError: # we're probably missing the http:// part, because it's a log entry, which lacks a url
  19. page, flags, user, comment = re.findall("\A\[\[(.*?)\]\]\s(.*?)\s\*\s(.*?)\s\*\s(.*?)\Z", msg)[0]
  20. url = "http://en.wikipedia.org/wiki/{}".format(page)
  21. flags = flags.strip() # flag tends to have a extraneous whitespace character at the end when it's a log entry
  22. self.is_edit = False # this is a log entry, not edit
  23. self.page, self.flags, self.url, self.user, self.comment = page, flags, url, user, comment
  24. def get_pretty(self):
  25. """make a nice, colorful message from self.msg to send to the front-end"""
  26. flags = self.flags
  27. event_type = flags # "New <event>:" if we don't know exactly what happened
  28. if "N" in flags:
  29. event_type = "page" # "New page:"
  30. elif flags == "delete":
  31. event_type = "deletion" # "New deletion:"
  32. elif flags == "protect":
  33. event_type = "protection" # "New protection:"
  34. elif flags == "create":
  35. event_type = "user" # "New user:"
  36. else:
  37. event_type = "edit" # "New edit:"
  38. if "B" in flags:
  39. event_type = "bot {}".format(event_type) # "New bot edit:"
  40. if "M" in flags:
  41. event_type = "minor {}".format(event_type) # "New minor edit:" OR "New minor bot edit:"
  42. if self.is_edit:
  43. pretty = "\x02New {0}\x0F: \x0314[[\x0307{1}\x0314]]\x0306 *\x0303 {2}\x0306 *\x0302 {3}\x0306 *\x0310 {4}".format(event_type, self.page, self.user, self.url, self.comment)
  44. else:
  45. pretty = "\x02New {0}\x0F: \x0303{1}\x0306 *\x0302 {2}\x0306 *\x0310 {3}".format(event_type, self.user, self.url, self.comment)
  46. return pretty