Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = "Nomz"
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.common.exceptions import NoSuchElementException
- import time
- ## Methods ##
- # Create the web driver, go to Twitch and login
- def CreateWebDriver():
- global browser, elem
- browser = webdriver.Firefox(executable_path="E:\\Desktop\\geckodriver")
- browser.get('https://www.twitch.tv/login')
- elem = browser.find_element_by_id("username")
- elem.send_keys(my_username + Keys.TAB + my_password + Keys.RETURN)
- time.sleep(5)
- # Go to a sponsored streamer and mute the stream
- def GoToStream():
- browser.get('https://www.twitch.tv/hardlydifficult')
- time.sleep(5)
- elem = browser.find_element_by_class_name("player-button--volume")
- elem.click()
- time.sleep(1)
- # CLick on the bits icon
- def ClickBitsIcon():
- elem = browser.find_element_by_class_name("bits-toggle")
- elem.click()
- time.sleep(1)
- # Click on the Get Bits button
- def ClickGetBits():
- elem = browser.find_element_by_class_name("js-buy-bits")
- elem.click()
- # Click on the Watch Ad button
- def WatchAd():
- elem = browser.find_element_by_class_name("bits-buy--button")
- elem.click()
- time.sleep(1)
- # Click on the Watch Ad button, refresh if not available and try again
- def TryWatchAd():
- while True:
- try:
- WatchAd()
- break
- except NoSuchElementException:
- browser.refresh()
- time.sleep(5)
- continue
- ## Logic ##
- # Set username and password
- my_username = "nomztest"
- my_password = "testnomz"
- # Create the driver, go to twitch and login
- CreateWebDriver()
- # Go to a sponsored streamer and mute the stream
- GoToStream()
- # Click on the bits icon
- ClickBitsIcon()
- # Click on the Get Bits button
- ClickGetBits()
- # Click on the Watch Ad button, refresh if not available and try again
- TryWatchAd()
- time.sleep(5)
- # Check for the Got It button that appears if an ad isn't available
- # If an ad isn't available, sleep for 30 minutes then check again
- # If an ad is available, break out of the loop
- while True:
- try:
- browser.find_element_by_class_name("button bits-footer__button")
- # wait 30 minutes then check for another ad
- time.sleep(4) # 1800 = 30 minutes
- TryWatchAd()
- continue
- except NoSuchElementException:
- print("Ad available")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement