-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_func.py
65 lines (48 loc) · 2.2 KB
/
bot_func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from random import uniform
class Automata(webdriver.Chrome):
def __init__(self, driver_path=r'/usr/local/bin/'):
self.driver_path = driver_path
self.usr = '' #specify the username
self.pw = '' #specify the password
self.randType = uniform(0.53, 0.58) #specify the typing speed (currently a random interval to wait between words, ca 106 WPM avg)
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
super(Automata, self).__init__(options=options)
self.implicitly_wait(15)
def open(self):
self.get("https://play.typeracer.com/")
def cookies_disagree(self):
disagree = self.find_element(By.XPATH, "//span[contains(., 'DISAGREE')]")
disagree.click()
def sign_in(self):
signin = self.find_element(By.XPATH, "//a[contains(., 'Sign In')]")
signin.click()
usr_textbox = self.find_element(By.CLASS_NAME, "gwt-TextBox")
usr_textbox.send_keys(self.usr)
pw_textbox = self.find_element(By.CLASS_NAME, "gwt-PasswordTextBox")
pw_textbox.send_keys(self.pw)
pw_textbox.send_keys(Keys.ENTER)
sleep(3) #although using sleep is not ideal, it seems to be the best solution here
close_popup = self.find_element(By.CSS_SELECTOR, 'g[class="xShape"]')
close_popup.click()
def start_race(self):
start = self.find_element(By.XPATH, "//a[contains(., 'Enter a Typing Race')]")
start.click()
sleep(2)
def type_race(self):
sleep(2)
text_ = self.find_element(By.CLASS_NAME, "txtInput")
state = self.find_element(By.CLASS_NAME, "gameStatusLabel")
text_full = self.find_element(By.CLASS_NAME, "inputPanel").text
wordlist = text_full.split()
wordlist = wordlist[:-3]
while True:
if "The race is on!" in state.text or "Go!" in state.text:
for word in wordlist:
text_.send_keys(word + " ")
sleep(self.randType)
break