Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import os
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from collections import deque
- driver = webdriver.Chrome('/usr/bin/chromedriver') # Optional argument, if not specified will search path.
- #Declares some needed variables and sets up a function for less clutter down the line.
- wait = WebDriverWait(driver, 10)
- def waitUntil (xpath):
- wait.until(
- EC.presence_of_element_located((By.XPATH, xpath))
- )
- #Navigates to the amazon page and logs in.
- driver.get('https://www.amazon.com/hz/mycd/myx/#/home/alexaPrivacy');
- waitUntil('//*[@id="ap_email"]')
- #Declares the email/password ids for it to use.
- empa = open("emailpassword.txt", "r")
- #Gets email/password from the file
- emailText = empa.readline()
- passwordText = empa.readlines()
- #Removes the first string of text in the table, allowing it to move on and put the password in.
- queue = deque(passwordText)
- queue.popleft()
- #
- username = driver.find_element_by_id("ap_email")
- password = driver.find_element_by_id("ap_password")
- submitButton = driver.find_element_by_id("signInSubmit")
- #Types the username and password in.
- username.send_keys(emailText)
- password.send_keys(passwordText)
- submitButton.click()
- #email = driver.find_element_by_xpath('//*[@id="ap_email"]')
- #email.sendKeys("email");
- #
- #Waits until the needed buttons load, and then goes to the correct privacy page
- waitUntil('/html/body/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div/div/div/div[2]/div[6]/div/div')
- driver.get('https://www.amazon.com/hz/mycd/myx/#/home/alexaPrivacy/');
- waitUntil('//*[@id="alexaPrivacy_overview_myx"]/div/div[2]/div/div[2]/div[3]')
- #Clicks on the button leading to the speech history of alexa
- arrowforhistory=driver.find_element_by_xpath('//*[@id="alexaPrivacy_overview_myx"]/div/div[2]/div/div[2]/div[3]')
- arrowforhistory.click()
- #Kills any tmux sessions so that they don't stack up.(Wouldn't recommend this if you use tmux at all)
- os.system("pkill -f tmux")
- time.sleep(2)
- #Opens a terminal logged into the tmux session
- os.system('xfce4-terminal -e "tmux -S roku"')
- time.sleep(2)
- #Uses telnet to connect to the roku and set up the terminal fully
- os.system("tmux -S roku send 'telnet 192.168.1.24 8080' ENTER")
- time.sleep(2)
- #os.system("screen -S roku -X -p 0 stuff $'telnet'")
- #os.system("tmux -S roku send ''")
- def reloadHistory ():
- ## Declare and click the drop down menu
- dateDropDown = driver.find_element_by_xpath('//*[@id="timePickerDesktop"]/span/span/span')
- dateDropDown.click()
- ## Declare and click the yesterday button in the drop down menu
- yesterdayDD = driver.find_element_by_id('timePickerDesktop_1')
- yesterdayDD.click()
- waitUntil('//*[@id="timePickerDesktop_1"]')
- ## Declare and click the today button in the drop down menu
- driver.switch_to_default_content()
- dateDropDown.click()
- waitUntil('//*[@id="mainInfo-0"]/div')
- waitUntil('//*[@id="timePickerDesktop_0"]')
- todayDD = driver.find_element_by_id('timePickerDesktop_0')
- #Using arrow keys because of a bug? Not sure why I have to use this. But I haven't found another way, yet.
- todayDD.send_keys(Keys.ARROW_UP)
- todayDD.send_keys(Keys.ENTER)
- while True:
- #Crash Protection
- waitUntil('//*[@id="mainInfo-0"]/div')
- reloadHistory()
- #Crash Protection
- waitUntil('//*[@id="mainInfo-0"]/div')
- latestQuestion = driver.find_element_by_xpath('//*[@id="mainInfo-0"]/div')
- #Crash protection
- waitUntil('//*[@id="mainInfo-0"]/div')
- #If, else statements for the buttons, should probably find a more elegant solution
- if "roku go down" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- print("recieved down")
- os.system("tmux -S roku send 'press down' ENTER")
- elif "roku go up" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press up' ENTER")
- print("recieved up")
- elif "roku go right" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press r' ENTER")
- print("recieved right")
- elif "roku go left" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press l' ENTER")
- print("recieved left")
- elif "roku go home" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press h' ENTER")
- print("recieved home")
- elif "roku go back" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press k' ENTER")
- print("recieved back")
- elif "roku pause" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press pause' ENTER")
- print("recieved pause")
- elif "roku play" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press play' ENTER")
- print("recieved play")
- elif "roku select" in latestQuestion.text:
- waitUntil('//*[@id="mainInfo-0"]/div')
- os.system("tmux -S roku send 'press s' ENTER")
- print("recieved select")
- else:
- print("nothing")
- print(latestQuestion.text)
- time.sleep(2) # Let the user actually see something!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement