listbot.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import time
  3. from selenium import webdriver
  4. PHANTOMJS_PATH = "tools/phantomjs/bin/phantomjs"
  5. SITE_URL = "http://127.0.0.1:43110"
  6. browser = webdriver.PhantomJS(executable_path=PHANTOMJS_PATH, service_log_path=os.path.devnull)
  7. browser.set_window_size(1400, 1000)
  8. browser.get("%s/1MaiL5gfBM1cyb4a8e3iiL8L5gXmoAJu27" % SITE_URL)
  9. #print " * LocalStorage:", browser.execute_script("return JSON.stringify(localStorage)")
  10. # Switch to inner frame
  11. browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))
  12. # Check if Inbox is active
  13. assert browser.execute_script("return window.Page.message_lists.getActive().title") == u"Inbox"
  14. # Setup new message checking script
  15. browser.execute_script("""
  16. window.replyUnreadMessage = function(cb) {
  17. var messages = window.Page.message_lists.getActive().messages
  18. var unread_messages = messages.filter(function(message) {
  19. console.log(message.row.subject)
  20. })
  21. console.log("---")
  22. setTimeout(function() {
  23. Page.message_create.handleSendClick()
  24. cb(true)
  25. }, 1000)
  26. }
  27. window.replyTimer = function() {
  28. setTimeout(function() { replyUnreadMessage(replyTimer) }, 1000)
  29. }
  30. replyTimer()
  31. """)
  32. browser.switch_to.default_content()
  33. last_log_line = 0
  34. while 1:
  35. lines = browser.get_log("browser")
  36. for line in lines[last_log_line:]:
  37. print line["message"].replace("(:)", "")
  38. last_log_line += 1
  39. time.sleep(5)