A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

earwigbot.py 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. EarwigBot
  5. A thin wrapper for EarwigBot's main bot code, specified by bot_script. This
  6. wrapper will automatically restart the bot when it shuts down (from !restart,
  7. for example). It requests the bot's password at startup and reuses it every
  8. time the bot restarts internally, so you do not need to re-enter the password
  9. after using !restart.
  10. For information about the bot as a whole, see the attached README.md file (in
  11. markdown format!) and the LICENSE for licensing information.
  12. """
  13. from getpass import getpass
  14. from subprocess import Popen, PIPE
  15. from os import path
  16. from sys import executable
  17. from time import sleep
  18. from core.config import verify_config
  19. __author__ = "Ben Kurtovic"
  20. __copyright__ = "Copyright (C) 2009, 2010, 2011 by Ben Kurtovic"
  21. __license__ = "MIT License"
  22. __version__ = "0.1-dev"
  23. __email__ = "ben.kurtovic@verizon.net"
  24. bot_script = path.join(path.dirname(path.abspath(__file__)), "core", "main.py")
  25. def main():
  26. print "EarwigBot v{0}\n".format(__version__)
  27. is_encrypted = verify_config()
  28. if is_encrypted: # passwords in the config file are encrypted
  29. key = getpass("Enter key to unencrypt bot passwords: ")
  30. else:
  31. key = None
  32. while 1:
  33. bot = Popen([executable, bot_script], stdin=PIPE)
  34. bot.communicate(key) # give the key to core.config.load_config()
  35. return_code = bot.wait()
  36. if return_code == 1:
  37. exit() # let critical exceptions in the subprocess cause us to
  38. # exit as well
  39. else:
  40. sleep(5) # sleep between bot runs following a non-critical
  41. # subprocess exit
  42. if __name__ == "__main__":
  43. try:
  44. main()
  45. except KeyboardInterrupt:
  46. print "\nKeyboardInterrupt: stopping bot wrapper."