Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. __author__ = "Nomz"
  2.  
  3. from selenium import webdriver
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.common.exceptions import NoSuchElementException
  6. import time
  7.  
  8. ## Methods ##
  9.  
  10. # Create the web driver, go to Twitch and login
  11. def CreateWebDriver():
  12.     global browser, elem
  13.     browser = webdriver.Firefox(executable_path="E:\\Desktop\\geckodriver")
  14.     browser.get('https://www.twitch.tv/login')
  15.     elem = browser.find_element_by_id("username")
  16.     elem.send_keys(my_username + Keys.TAB + my_password + Keys.RETURN)
  17.     time.sleep(5)
  18.  
  19.  
  20. # Go to a sponsored streamer and mute the stream
  21. def GoToStream():
  22.     browser.get('https://www.twitch.tv/hardlydifficult')
  23.     time.sleep(5)
  24.     elem = browser.find_element_by_class_name("player-button--volume")
  25.     elem.click()
  26.     time.sleep(1)
  27.  
  28. # CLick on the bits icon
  29. def ClickBitsIcon():
  30.     elem = browser.find_element_by_class_name("bits-toggle")
  31.     elem.click()
  32.     time.sleep(1)
  33.  
  34. # Click on the Get Bits button
  35. def ClickGetBits():
  36.     elem = browser.find_element_by_class_name("js-buy-bits")
  37.     elem.click()
  38.  
  39.  
  40. # Click on the Watch Ad button
  41. def WatchAd():
  42.     elem = browser.find_element_by_class_name("bits-buy--button")
  43.     elem.click()
  44.     time.sleep(1)
  45.  
  46. # Click on the Watch Ad button, refresh if not available and try again
  47. def TryWatchAd():
  48.     while True:
  49.         try:
  50.             WatchAd()
  51.             break
  52.         except NoSuchElementException:
  53.             browser.refresh()
  54.             time.sleep(5)
  55.             continue
  56.  
  57. ## Logic ##
  58.  
  59. # Set username and password
  60. my_username = "nomztest"
  61. my_password = "testnomz"
  62.  
  63.  
  64. # Create the driver, go to twitch and login
  65. CreateWebDriver()
  66.  
  67. # Go to a sponsored streamer and mute the stream
  68. GoToStream()
  69.  
  70. # Click on the bits icon
  71. ClickBitsIcon()
  72.  
  73. # Click on the Get Bits button
  74. ClickGetBits()
  75.  
  76. # Click on the Watch Ad button, refresh if not available and try again
  77. TryWatchAd()
  78. time.sleep(5)
  79.  
  80. # Check for the Got It button that appears if an ad isn't available
  81. # If an ad isn't available, sleep for 30 minutes then check again
  82. # If an ad is available, break out of the loop
  83. while True:
  84.     try:
  85.         browser.find_element_by_class_name("button bits-footer__button")
  86.         # wait 30 minutes then check for another ad
  87.         time.sleep(4) # 1800 = 30 minutes
  88.         TryWatchAd()
  89.         continue
  90.     except NoSuchElementException:
  91.        print("Ad available")
  92.        break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement