Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. from selenium import webdriver #Import the webdriver
  2. from selenium.webdriver.common.keys import Keys #Import the ability to input keys (I think)
  3. import time #Import time (useless I think but shhh)
  4. import datetime #Import the datetime (Actual module (That comes with python) used for time command, do not delete)
  5.  
  6. #Open firefox browser (Change for ie)
  7. browser = webdriver.Firefox()
  8. #GO to band page
  9. browser.get('https://auth.band.us/email_login?keep_login=false ')
  10. #Find the text box id's for username and password
  11. username = browser.find_element_by_id("input_email")
  12. password = browser.find_element_by_id("input_password")
  13. #Input username and password
  14. username.send_keys("YOUR EMAIL")
  15. password.send_keys("YOUR PASSWORD")
  16. #Enter the username and password
  17. password.send_keys(Keys.ENTER)
  18.  
  19. #Second log in attempt, I really dont need to re explain what it does.
  20. browser.get('https://auth.band.us/email_login?keep_login=false ')
  21. username = browser.find_element_by_id("input_email")
  22. password = browser.find_element_by_id("input_password")
  23. username.send_keys("YOUR EMAIL")
  24. password.send_keys("YOUR PASSWORD")
  25. password.send_keys(Keys.ENTER)
  26. time.sleep(5)
  27. #GO to cloak ooc chat
  28. browser.get('http://band.us/chat/chattingRoom?channelID=CAd3ok&bandNo=62973656')
  29. #Wait for chat load
  30. time.sleep(5)
  31. #Find the message box element
  32. chat = browser.find_element_by_id("write_comment_view20")
  33. #Starting message
  34. chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan has been activated")
  35. #Press enter
  36. chat.send_keys(Keys.ENTER)
  37. #Create the variable used to count messages
  38. count = 0
  39. #Main brunt of the code, this will constantly check for messages
  40. while True:
  41. #Arbitrary wait timer that helps code work... somehow,
  42. time.sleep(6)
  43. #Refresh the browser, what do you think it was going to do?
  44. browser.refresh()
  45. #More waiting, this is what slows down my code
  46. time.sleep(6)
  47. #Ok, so this top line checks for every single element that contains a txt class which is all the messages in band. The reversed functions means it checks from the bottom.
  48. for element in reversed(browser.find_elements_by_class_name("txt")):
  49. #This adds one to the count
  50. count +=1
  51. #If the count equals 4 then rest the count and break the loop. This means it will bring the four most recent messages in the band chat
  52. if count == 4:
  53. count = 0
  54. break
  55. #Print all of the messages into the console, useful for debugging. I recommend you keep the code there
  56. print(element.text)
  57. #Puts the element text into a variable so I can use it in loops and ifs
  58. chat_thing = element.text
  59. #This is for the help command you love spamming so much
  60. if chat_thing == "!help": #If one of the text elements equals !help then:
  61. #Find the message element again
  62. chat = browser.find_element_by_id("write_comment_view20")
  63. #Type in this opening statement
  64. chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan here, I have some interesting things to tell")
  65. #Press enter (Duh)
  66. chat.send_keys(Keys.ENTER)
  67. #Type in the second message
  68. chat.send_keys("I can assist you with these commands, all commands must be prefixed with !")
  69. #Press enter
  70. chat.send_keys(Keys.ENTER)
  71. #Type in the third message
  72. chat.send_keys("help")
  73. #Press enter
  74. chat.send_keys(Keys.ENTER)
  75. #This is the time command. I will keep it for reasons
  76. if chat_thing == "!time":
  77. #Find the message element
  78. chat = browser.find_element_by_id("write_comment_view20")
  79. #Find out the date and time right now
  80. now = datetime.datetime.now()
  81. #Find out what hour it is and convert it to a string (that's what str() does)
  82. hour = str(now.hour)
  83. #Find the minutes
  84. minute = str(now.minute)
  85. #Find the seconds
  86. second = str(now.second)
  87. #Send a message saying "Calcualting time"
  88. chat.send_keys("Calculating time")
  89. #Press enter
  90. chat.send_keys(Keys.ENTER)
  91. #Send the variables hour, minute and second in the format hour:minute:second
  92. chat.send_keys(hour, ":", minute, ":", second)
  93. #Press enter
  94. chat.send_keys(Keys.ENTER)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement