Advertisement
Guest User

tpcyborgedit1

a guest
Jun 10th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import getpass
  3. import logging
  4. import logging.handlers
  5. import os
  6. import random
  7. import sys
  8.  
  9. import chatexchange.client
  10. import chatexchange.events
  11.  
  12.  
  13. logger = logging.getLogger(__name__)
  14.  
  15.  
  16. def main():
  17.     setup_logging()
  18.  
  19.     # Run `. setp.sh` to set the below testing environment variables
  20.  
  21.     host_id = 'stackexchange.com'
  22.     room_id = '14219'  # Charcoal Chatbot Sandbox
  23.  
  24.     if 'ChatExchangeU' in os.environ:
  25.         email = os.environ['ChatExchangeU']
  26.     else:
  27.         email = raw_input("Email: ")
  28.     if 'ChatExchangeP' in os.environ:
  29.         password = os.environ['ChatExchangeP']
  30.     else:
  31.         password = getpass.getpass("Password: ")
  32.  
  33.     client = chatexchange.client.Client(host_id)
  34.     client.login(email, password)
  35.  
  36.     room = client.get_room(room_id)
  37.     room.join()
  38.     room.watch(on_message)
  39.  
  40.     print "(You are now in room #%s on %s.)" % (room_id, host_id)
  41.     while True:
  42.         message = raw_input("<< ")
  43.         room.send_message(message)
  44.  
  45.     client.logout()
  46.  
  47.  
  48. def on_message(message, client):
  49.     if not isinstance(message, chatexchange.events.UserEntered):
  50.     room.send_message("@"+message.user.name+" you have entered the domain of the Zombie Pony Queen!")
  51.  
  52.  
  53. def setup_logging():
  54.     logging.basicConfig(level=logging.INFO)
  55.     logger.setLevel(logging.DEBUG)
  56.  
  57.     # In addition to the basic stderr logging configured globally
  58.     # above, we'll use a log file for chatexchange.client.
  59.     wrapper_logger = logging.getLogger('chatexchange.client')
  60.     wrapper_handler = logging.handlers.TimedRotatingFileHandler(
  61.         filename='client.log',
  62.         when='midnight', delay=True, utc=True, backupCount=7,
  63.     )
  64.     wrapper_handler.setFormatter(logging.Formatter(
  65.         "%(asctime)s: %(levelname)s: %(threadName)s: %(message)s"
  66.     ))
  67.     wrapper_logger.addHandler(wrapper_handler)
  68.  
  69.  
  70. if __name__ == '__main__':
  71.     main(*sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement