A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

55 行
1.7 KiB

  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. EarwigBot
  5. A thin wrapper for EarwigBot's main bot code, located in core/main.py. 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 sys import executable
  16. from time import sleep
  17. from core.config import verify_config
  18. __author__ = "Ben Kurtovic"
  19. __copyright__ = "Copyright (c) 2009-2011 by Ben Kurtovic"
  20. __license__ = "MIT License"
  21. __version__ = "0.1dev"
  22. __email__ = "ben.kurtovic@verizon.net"
  23. def main():
  24. print "EarwigBot v{0}\n".format(__version__)
  25. is_encrypted = verify_config()
  26. if is_encrypted: # passwords in the config file are encrypted
  27. key = getpass("Enter key to unencrypt bot passwords: ")
  28. else:
  29. key = None
  30. while 1:
  31. bot = Popen([executable, 'core/main.py'], stdin=PIPE)
  32. bot.communicate(key) # give the key to core.config.load()
  33. return_code = bot.wait()
  34. if return_code == 1:
  35. exit() # let critical exceptions in the subprocess cause us to
  36. # exit as well
  37. else:
  38. sleep(5) # sleep between bot runs following a non-critical
  39. # subprocess exit
  40. if __name__ == "__main__":
  41. try:
  42. main()
  43. except KeyboardInterrupt:
  44. print "\nKeyboardInterrupt: stopping bot wrapper."