Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cfscrape
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from time import sleep
- from datetime import datetime
- with open("info.txt", "r") as f:
- info = f.read().split()
- EMAIL, PASSWORD, USERNAME = info[0], info[1], info[2]
- TRADE_URL = f'https://rocket-league.com/trades/{USERNAME}'
- def initial_setup():
- '''Signs user into website, sets up Selenium'''
- scraper = cfscrape.create_scraper()
- tokens = scraper.get_tokens('https://rocket-league.com')
- driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
- driver.add_cookie({
- 'domain': '.rocket-league.com',
- 'name': tokens[0]['__cfduid'],
- 'value': tokens[0]['cf_clearance'],
- 'path': '/',
- 'expires': None
- })
- driver.get('http://rocket-league.com/training/')
- sleep(10)
- email = driver.find_element_by_name('email')
- email.send_keys(EMAIL)
- password = driver.find_element_by_name('password')
- password.send_keys(PASSWORD)
- password.send_keys(Keys.RETURN)
- return driver
- def check_items(driver):
- '''Checks each item in the users trade page, if older than 15 mins
- edits it'''
- driver.get(TRADE_URL)
- trade_amt = driver.find_elements_by_class_name('rlg-trade-display-header') # Finds how many trades the user currently has
- # Loops through each trade
- for i in range(1, len(trade_amt) + 1):
- try:
- text = driver.find_element_by_xpath(f"/html/body/main/div/div/div/div[4]/div[{i}]/div[1]/div/div/span").text.split()
- print(f'Trade {i} was last updated {text[1]} {text[2]} ago')
- if text[2] == "seconds":
- continue
- else:
- if text[2] in ["hour", "hours"] or int(text[1]) >= 15:
- # Goes to actual trade
- driver.find_element_by_xpath(f'/html/body/main/div/div/div/div[4]/div[{i}]/div[1]/a/div').click()
- sleep(2)
- # Goes to edit page
- driver.find_element_by_xpath('/html/body/main/div/div/div/div[2]/a[1]').click()
- sleep(2)
- # Edits the text with an extra dot if a dot is not there
- # Otherwise removes the dot
- textbox = driver.find_element_by_name('note')
- if textbox.text.endswith('.'):
- textbox.send_keys(Keys.BACKSPACE)
- else:
- textbox.send_keys('.')
- # Save changes button
- driver.find_element_by_name('btnSubmit').click()
- # Sleep for 2 seconds to ensure it works
- # Return to trade page to go onto next trade
- sleep(2)
- driver.get(TRADE_URL)
- except Exception as e:
- # If anything fails, it will just go back to the trade page
- # and continute the loop
- driver.get(TRADE_URL)
- print(e)
- def main():
- driver = initial_setup()
- while True:
- now = datetime.now()
- print(f'Running: {now.hour}:{now.minute} - {now.day}/{now.month}/{now.year}')
- check_items(driver)
- print("\n")
- sleep(15)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement