Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver #Import the webdriver
- from selenium.webdriver.common.keys import Keys #Import the ability to input keys (I think)
- import time #Import time (useless I think but shhh)
- import datetime #Import the datetime (Actual module (That comes with python) used for time command, do not delete)
- #Open firefox browser (Change for ie)
- browser = webdriver.Firefox()
- #GO to band page
- browser.get('https://auth.band.us/email_login?keep_login=false ')
- #Find the text box id's for username and password
- username = browser.find_element_by_id("input_email")
- password = browser.find_element_by_id("input_password")
- #Input username and password
- username.send_keys("YOUR EMAIL")
- password.send_keys("YOUR PASSWORD")
- #Enter the username and password
- password.send_keys(Keys.ENTER)
- #Second log in attempt, I really dont need to re explain what it does.
- browser.get('https://auth.band.us/email_login?keep_login=false ')
- username = browser.find_element_by_id("input_email")
- password = browser.find_element_by_id("input_password")
- username.send_keys("YOUR EMAIL")
- password.send_keys("YOUR PASSWORD")
- password.send_keys(Keys.ENTER)
- time.sleep(5)
- #GO to cloak ooc chat
- browser.get('http://band.us/chat/chattingRoom?channelID=CAd3ok&bandNo=62973656')
- #Wait for chat load
- time.sleep(5)
- #Find the message box element
- chat = browser.find_element_by_id("write_comment_view20")
- #Starting message
- chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan has been activated")
- #Press enter
- chat.send_keys(Keys.ENTER)
- #Create the variable used to count messages
- count = 0
- #Main brunt of the code, this will constantly check for messages
- while True:
- #Arbitrary wait timer that helps code work... somehow,
- time.sleep(6)
- #Refresh the browser, what do you think it was going to do?
- browser.refresh()
- #More waiting, this is what slows down my code
- time.sleep(6)
- #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.
- for element in reversed(browser.find_elements_by_class_name("txt")):
- #This adds one to the count
- count +=1
- #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
- if count == 4:
- count = 0
- break
- #Print all of the messages into the console, useful for debugging. I recommend you keep the code there
- print(element.text)
- #Puts the element text into a variable so I can use it in loops and ifs
- chat_thing = element.text
- #This is for the help command you love spamming so much
- if chat_thing == "!help": #If one of the text elements equals !help then:
- #Find the message element again
- chat = browser.find_element_by_id("write_comment_view20")
- #Type in this opening statement
- chat.send_keys("Father O'Mally O'Connel O'Ciero O'Riley O'Brian O'Sullivan here, I have some interesting things to tell")
- #Press enter (Duh)
- chat.send_keys(Keys.ENTER)
- #Type in the second message
- chat.send_keys("I can assist you with these commands, all commands must be prefixed with !")
- #Press enter
- chat.send_keys(Keys.ENTER)
- #Type in the third message
- chat.send_keys("help")
- #Press enter
- chat.send_keys(Keys.ENTER)
- #This is the time command. I will keep it for reasons
- if chat_thing == "!time":
- #Find the message element
- chat = browser.find_element_by_id("write_comment_view20")
- #Find out the date and time right now
- now = datetime.datetime.now()
- #Find out what hour it is and convert it to a string (that's what str() does)
- hour = str(now.hour)
- #Find the minutes
- minute = str(now.minute)
- #Find the seconds
- second = str(now.second)
- #Send a message saying "Calcualting time"
- chat.send_keys("Calculating time")
- #Press enter
- chat.send_keys(Keys.ENTER)
- #Send the variables hour, minute and second in the format hour:minute:second
- chat.send_keys(hour, ":", minute, ":", second)
- #Press enter
- chat.send_keys(Keys.ENTER)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement