A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

editcount.py 1.1 KiB

13 years ago
13 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. from urllib import quote_plus
  3. from classes import BaseCommand
  4. import wiki
  5. class Command(BaseCommand):
  6. """Return a user's edit count."""
  7. name = "editcount"
  8. def check(self, data):
  9. commands = ["ec", "editcount"]
  10. if data.is_command and data.command in commands:
  11. return True
  12. return False
  13. def process(self, data):
  14. if not data.args:
  15. name = data.nick
  16. else:
  17. name = ' '.join(data.args)
  18. site = wiki.get_site()
  19. site._maxlag = None
  20. user = site.get_user(name)
  21. try:
  22. count = user.editcount()
  23. except wiki.UserNotFoundError:
  24. msg = "the user \x0302{0}\x0301 does not exist."
  25. self.connection.reply(data, msg.format(name))
  26. return
  27. safe = quote_plus(user.name())
  28. url = "http://toolserver.org/~soxred93/pcount/index.php?name={0}&lang=en&wiki=wikipedia"
  29. msg = "\x0302{0}\x0301 has {1} edits ({2})."
  30. self.connection.reply(data, msg.format(name, count, url.format(safe)))