A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
13 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding: utf-8 -*-
  2. import re
  3. from classes import BaseCommand
  4. import wiki
  5. class Command(BaseCommand):
  6. """Get information about an AFC submission by name."""
  7. name = "report"
  8. def process(self, data):
  9. self.site = wiki.get_site()
  10. self.data = data
  11. if not data.args:
  12. msg = "what submission do you want me to give information about?"
  13. self.connection.reply(data, msg)
  14. return
  15. title = ' '.join(data.args)
  16. title = title.replace("http://en.wikipedia.org/wiki/", "")
  17. title = title.replace("http://enwp.org/", "").strip()
  18. # Given '!report Foo', first try [[Foo]]:
  19. if self.report(title):
  20. return
  21. # Then try [[Wikipedia:Articles for creation/Foo]]:
  22. title2 = "".join(("Wikipedia:Articles for creation/", title))
  23. if self.report(title2):
  24. return
  25. # Then try [[Wikipedia talk:Articles for creation/Foo]]:
  26. title3 = "".join(("Wikipedia talk:Articles for creation/", title))
  27. if self.report(title3):
  28. return
  29. msg = "submission \x0302{0}\x0301 not found.".format(title)
  30. self.connection.reply(data, msg)
  31. def report(self, title):
  32. data = self.data
  33. page = self.site.get_page(title, follow_redirects=False)
  34. if not page.exists()[0]:
  35. return
  36. url = page.url().replace("en.wikipedia.org/wiki", "enwp.org")
  37. short = re.sub("wikipedia( talk)?\:articles for creation\/", "", title,
  38. flags=re.IGNORECASE)
  39. status = self.get_status(page)
  40. user = self.site.get_user(page.creator())
  41. user_name = user.name()
  42. user_url = user.get_talkpage().url()
  43. msg1 = "AfC submission report for \x0302{0}\x0301 ({1}):"
  44. msg2 = "Status: \x0303{0}\x0301"
  45. msg3 = "Submitted by \x0302{0}\x0301 ({1})"
  46. if status == "accepted":
  47. msg3 = "Reviewed by \x0302{0}\x0301 ({1})"
  48. self.connection.reply(data, msg1.format(short, url))
  49. self.connection.say(data.chan, msg2.format(status))
  50. self.connection.say(data.chan, msg3.format(user_name, user_url))
  51. return True
  52. def get_status(self, page):
  53. content = page.get()
  54. if page.is_redirect():
  55. target = page.get_redirect_target()
  56. if self.site.get_page(target).namespace() == 0:
  57. return "accepted"
  58. return "redirect"
  59. if re.search("\{\{afc submission\|r\|(.*?)\}\}", content, re.I):
  60. return "being reviewed"
  61. if re.search("\{\{afc submission\|\|(.*?)\}\}", content, re.I):
  62. return "pending"
  63. if re.search("\{\{afc submission\|d\|(.*?)\}\}", content, re.I):
  64. regex = "\{\{afc submission\|d\|(.*?)(\||\}\})"
  65. try:
  66. reason = re.findall(regex, content, re.I)[0][0]
  67. except IndexError:
  68. return "declined"
  69. return "declined with reason \"{0}\"".format(reason)
  70. return "unkown"