Advertisement
The_insane_Scientist

Untitled

Nov 15th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. import selenium.common.exceptions
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium import webdriver #Import the webdriver
  6. from selenium.webdriver.common.keys import Keys #Import the ability to input keys (I think)
  7. import time #Import time (useless I think but shhh)
  8. import datetime #Import the datetime (Actual module (That comes with python) used for time command, do not delete)
  9. from cleverbot import Cleverbot
  10. import os
  11. #Open firefox browser (Change for ie)
  12. browser = webdriver.Firefox()
  13. #GO to band page
  14. browser.get('https://auth.band.us/email_login?keep_login=false ')
  15. #Find the text box id's for username and password
  16. username = browser.find_element_by_id("input_email")
  17. password = browser.find_element_by_id("input_password")
  18. #Input username and password
  19. username.send_keys("USERNAME")
  20. password.send_keys("Password")
  21. #Enter the username and password
  22. password.send_keys(Keys.ENTER)
  23.  
  24. #Second log in attempt, I really dont need to re explain what it does.
  25. browser.get('https://auth.band.us/email_login?keep_login=false ')
  26. username = browser.find_element_by_id("input_email")
  27. password = browser.find_element_by_id("input_password")
  28. username.send_keys("USERNAME")
  29. password.send_keys("PASSWORD")
  30. password.send_keys(Keys.ENTER)
  31. time.sleep(2)
  32. #GO to cloak Out of character chat chat
  33. browser.get('http://band.us/chat/chattingRoom?channelID=CAd3ok&bandNo=62973656')
  34. #Wait for chat load
  35. time.sleep(5)
  36. #Find the message box element
  37. chat = browser.find_element_by_id("write_comment_view20")
  38. #Starting message
  39. #chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan has been activated")
  40. #Press enter
  41. chat.send_keys(Keys.ENTER)
  42. #Create the variable used to count messages
  43. browser.refresh()
  44. time.sleep(10)
  45. cb = Cleverbot()
  46. count = 0
  47. msgold = 0
  48. chat_thing = 1
  49. chat = browser.find_element_by_id("write_comment_view20")
  50. def anrp_chat_on():
  51. time.sleep(7)
  52. newcount = 0
  53. for element in reversed(browser.find_elements_by_class_name("txt")):
  54. newcount +=1
  55. if newcount == 2:
  56. newcount = 0
  57. break
  58. chat_thing = element.text
  59. cbAnswer = cb.ask(chat_thing)
  60. chat = browser.find_element_by_id("write_comment_view20")
  61. chat.send_keys(cbAnswer)
  62. chat.send_keys(Keys.ENTER)
  63. def anrp_chat_offline():
  64. cbAnswer = None
  65.  
  66. #Main brunt of the code, this will constantly check for messages
  67. while True:
  68. try:
  69. for element in reversed(browser.find_elements_by_class_name("txt")):
  70. count +=1
  71. if count == 3:
  72. chat_thing = str(element.text)
  73. #If the new message isn't a repeat it will display the newest message and the previous, non-repeat message
  74. if chat_thing != msgold:
  75. print (chat_thing)
  76. print ("New message")
  77. print (msgold)
  78. print ("This is the old message")
  79. msgold = chat_thing
  80. if chat_thing == "!spam":
  81. while True:
  82. chat = browser.find_element_by_id("write_comment_view20")
  83. chat.send_keys("I AM A SPAM BOT, SPAMMING CHATS, SPAMMY SPAMMY SPAAAM!")
  84. chat.send_keys(Keys.ENTER)
  85. chat.send_keys(Keys.ENTER)
  86. #Help command
  87. if chat_thing == "!help":
  88. chat = browser.find_element_by_id("write_comment_view20")
  89. chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan here, I have some interesting things to tell")
  90. chat.send_keys(Keys.ENTER)
  91. chat.send_keys("I can assist you using these commands, all commands must be prefixed with !")
  92. chat.send_keys(Keys.ENTER)
  93. chat.send_keys("help, time")
  94. chat.send_keys(Keys.ENTER)
  95. #!Time command
  96. if chat_thing == "!time":
  97. chat = browser.find_element_by_id("write_comment_view20")
  98. now = datetime.datetime.now()
  99. hour = str(now.hour)
  100. minute = str(now.minute)
  101. second = str(now.second)
  102. chat.send_keys("Calculating time")
  103. chat.send_keys(Keys.ENTER)
  104. chat.send_keys(hour, ":", minute, ":", second)
  105. chat.send_keys(Keys.ENTER)
  106. if chat_thing == "anrp_on":
  107. while True:
  108. anrp_chat_on()
  109. if chat_thing == "anrp_off":
  110. anrp_chat_off()
  111. count = 0
  112. break
  113. except selenium.common.exceptions.StaleElementReferenceException:
  114. print("Stale dom")
  115.  
  116. """#Refresh the browser, what do you think it was going to do?
  117. browser.refresh()
  118. #More waiting, this is what slows down my code
  119. time.sleep(7)
  120. for element in reversed(browser.find_elements_by_class_name("txt")):
  121. count +=1
  122. if count == 2:
  123. count = 0
  124. break
  125. print(element.text)
  126. chat_thing = element.text"""
  127.  
  128. """
  129. #this gathers the text without refreshing all the time lol (Zeke code)
  130. for element in reversed(browser.find_elements_by_class_name("txt")):
  131. count +=1
  132. if count == 3:
  133. count = 0
  134. break
  135. print(element.text)
  136. chat_thing = element.text
  137. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement