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

13 роки тому
13 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.site._maxlag = None
  11. self.data = data
  12. if not data.args:
  13. msg = "what submission do you want me to give information about?"
  14. self.connection.reply(data, msg)
  15. return
  16. title = ' '.join(data.args)
  17. title = title.replace("http://en.wikipedia.org/wiki/", "")
  18. title = title.replace("http://enwp.org/", "").strip()
  19. # Given '!report Foo', first try [[Foo]]:
  20. if self.report(title):
  21. return
  22. # Then try [[Wikipedia:Articles for creation/Foo]]:
  23. title2 = "".join(("Wikipedia:Articles for creation/", title))
  24. if self.report(title2):
  25. return
  26. # Then try [[Wikipedia talk:Articles for creation/Foo]]:
  27. title3 = "".join(("Wikipedia talk:Articles for creation/", title))
  28. if self.report(title3):
  29. return
  30. msg = "submission \x0302{0}\x0301 not found.".format(title)
  31. self.connection.reply(data, msg)
  32. def report(self, title):
  33. data = self.data
  34. page = self.site.get_page(title, follow_redirects=False)
  35. if not page.exists()[0]:
  36. return
  37. url = page.url().replace("en.wikipedia.org/wiki", "enwp.org")
  38. short = re.sub("wikipedia( talk)?\:articles for creation\/", "", title,
  39. flags=re.IGNORECASE)
  40. status = self.get_status(page)
  41. user = self.site.get_user(page.creator())
  42. user_name = user.name()
  43. user_url = user.get_talkpage().url()
  44. msg1 = "AfC submission report for \x0302{0}\x0301 ({1}):"
  45. msg2 = "Status: \x0303{0}\x0301"
  46. msg3 = "Submitted by \x0302{0}\x0301 ({1})"
  47. if status == "accepted":
  48. msg3 = "Reviewed by \x0302{0}\x0301 ({1})"
  49. self.connection.reply(data, msg1.format(short, url))
  50. self.connection.say(data.chan, msg2.format(status))
  51. self.connection.say(data.chan, msg3.format(user_name, user_url))
  52. return True
  53. def get_status(self, page):
  54. content = page.get()
  55. if page.is_redirect():
  56. target = page.get_redirect_target()
  57. if self.site.get_page(target).namespace() == 0:
  58. return "accepted"
  59. return "redirect"
  60. elif re.search("\{\{afc submission\|r\|(.*?)\}\}", content, re.I):
  61. return "being reviewed"
  62. elif re.search("\{\{afc submission\|h?\|(.*?)\}\}", content, re.I):
  63. return "pending"
  64. elif re.search("\{\{afc submission\|t\|(.*?)\}\}", content, re.I):
  65. return "unsubmitted draft"
  66. elif re.search("\{\{afc submission\|d\|(.*?)\}\}", content, re.I):
  67. regex = "\{\{afc submission\|d\|(.*?)(\||\}\})"
  68. try:
  69. reason = re.findall(regex, content, re.I)[0][0]
  70. except IndexError:
  71. return "declined"
  72. return "declined with reason \"{0}\"".format(reason)
  73. return "unkown"