Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. import time
  2. import os
  3. from selenium import webdriver
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.common.by import By
  6. from selenium.webdriver.support.wait import WebDriverWait
  7. from selenium.webdriver.support import expected_conditions as EC
  8. from collections import deque
  9.  
  10. driver = webdriver.Chrome('/usr/bin/chromedriver') # Optional argument, if not specified will search path.
  11. #Declares some needed variables and sets up a function for less clutter down the line.
  12. wait = WebDriverWait(driver, 10)
  13. def waitUntil (xpath):
  14. wait.until(
  15. EC.presence_of_element_located((By.XPATH, xpath))
  16. )
  17.  
  18. #Navigates to the amazon page and logs in.
  19. driver.get('https://www.amazon.com/hz/mycd/myx/#/home/alexaPrivacy');
  20. waitUntil('//*[@id="ap_email"]')
  21. #Declares the email/password ids for it to use.
  22. empa = open("emailpassword.txt", "r")
  23. #Gets email/password from the file
  24. emailText = empa.readline()
  25. passwordText = empa.readlines()
  26. #Removes the first string of text in the table, allowing it to move on and put the password in.
  27. queue = deque(passwordText)
  28. queue.popleft()
  29. #
  30. username = driver.find_element_by_id("ap_email")
  31. password = driver.find_element_by_id("ap_password")
  32. submitButton = driver.find_element_by_id("signInSubmit")
  33. #Types the username and password in.
  34. username.send_keys(emailText)
  35. password.send_keys(passwordText)
  36. submitButton.click()
  37. #email = driver.find_element_by_xpath('//*[@id="ap_email"]')
  38. #email.sendKeys("email");
  39. #
  40. #Waits until the needed buttons load, and then goes to the correct privacy page
  41. 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')
  42. driver.get('https://www.amazon.com/hz/mycd/myx/#/home/alexaPrivacy/');
  43. waitUntil('//*[@id="alexaPrivacy_overview_myx"]/div/div[2]/div/div[2]/div[3]')
  44. #Clicks on the button leading to the speech history of alexa
  45. arrowforhistory=driver.find_element_by_xpath('//*[@id="alexaPrivacy_overview_myx"]/div/div[2]/div/div[2]/div[3]')
  46. arrowforhistory.click()
  47. #Kills any tmux sessions so that they don't stack up.(Wouldn't recommend this if you use tmux at all)
  48. os.system("pkill -f tmux")
  49. time.sleep(2)
  50. #Opens a terminal logged into the tmux session
  51. os.system('xfce4-terminal -e "tmux -S roku"')
  52. time.sleep(2)
  53. #Uses telnet to connect to the roku and set up the terminal fully
  54. os.system("tmux -S roku send 'telnet 192.168.1.24 8080' ENTER")
  55. time.sleep(2)
  56. #os.system("screen -S roku -X -p 0 stuff $'telnet'")
  57. #os.system("tmux -S roku send ''")
  58.  
  59.  
  60.  
  61. def reloadHistory ():
  62. ## Declare and click the drop down menu
  63. dateDropDown = driver.find_element_by_xpath('//*[@id="timePickerDesktop"]/span/span/span')
  64. dateDropDown.click()
  65. ## Declare and click the yesterday button in the drop down menu
  66. yesterdayDD = driver.find_element_by_id('timePickerDesktop_1')
  67. yesterdayDD.click()
  68. waitUntil('//*[@id="timePickerDesktop_1"]')
  69. ## Declare and click the today button in the drop down menu
  70. driver.switch_to_default_content()
  71. dateDropDown.click()
  72. waitUntil('//*[@id="mainInfo-0"]/div')
  73. waitUntil('//*[@id="timePickerDesktop_0"]')
  74. todayDD = driver.find_element_by_id('timePickerDesktop_0')
  75. #Using arrow keys because of a bug? Not sure why I have to use this. But I haven't found another way, yet.
  76. todayDD.send_keys(Keys.ARROW_UP)
  77. todayDD.send_keys(Keys.ENTER)
  78.  
  79.  
  80. while True:
  81. #Crash Protection
  82. waitUntil('//*[@id="mainInfo-0"]/div')
  83. reloadHistory()
  84. #Crash Protection
  85. waitUntil('//*[@id="mainInfo-0"]/div')
  86. latestQuestion = driver.find_element_by_xpath('//*[@id="mainInfo-0"]/div')
  87. #Crash protection
  88. waitUntil('//*[@id="mainInfo-0"]/div')
  89. #If, else statements for the buttons, should probably find a more elegant solution
  90. if "roku go down" in latestQuestion.text:
  91. waitUntil('//*[@id="mainInfo-0"]/div')
  92. print("recieved down")
  93. os.system("tmux -S roku send 'press down' ENTER")
  94. elif "roku go up" in latestQuestion.text:
  95. waitUntil('//*[@id="mainInfo-0"]/div')
  96. os.system("tmux -S roku send 'press up' ENTER")
  97. print("recieved up")
  98. elif "roku go right" in latestQuestion.text:
  99. waitUntil('//*[@id="mainInfo-0"]/div')
  100. os.system("tmux -S roku send 'press r' ENTER")
  101. print("recieved right")
  102. elif "roku go left" in latestQuestion.text:
  103. waitUntil('//*[@id="mainInfo-0"]/div')
  104. os.system("tmux -S roku send 'press l' ENTER")
  105. print("recieved left")
  106. elif "roku go home" in latestQuestion.text:
  107. waitUntil('//*[@id="mainInfo-0"]/div')
  108. os.system("tmux -S roku send 'press h' ENTER")
  109. print("recieved home")
  110. elif "roku go back" in latestQuestion.text:
  111. waitUntil('//*[@id="mainInfo-0"]/div')
  112. os.system("tmux -S roku send 'press k' ENTER")
  113. print("recieved back")
  114. elif "roku pause" in latestQuestion.text:
  115. waitUntil('//*[@id="mainInfo-0"]/div')
  116. os.system("tmux -S roku send 'press pause' ENTER")
  117. print("recieved pause")
  118. elif "roku play" in latestQuestion.text:
  119. waitUntil('//*[@id="mainInfo-0"]/div')
  120. os.system("tmux -S roku send 'press play' ENTER")
  121. print("recieved play")
  122. elif "roku select" in latestQuestion.text:
  123. waitUntil('//*[@id="mainInfo-0"]/div')
  124. os.system("tmux -S roku send 'press s' ENTER")
  125. print("recieved select")
  126. else:
  127. print("nothing")
  128. print(latestQuestion.text)
  129. time.sleep(2) # Let the user actually see something!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement