This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
160 lines (125 loc) · 5.68 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from selenium import webdriver
from time import sleep
from random import randint
from secrets import username, password
import csv
class ReviseBot:
def __init__(self):
self.driver = webdriver.Chrome(executable_path='./chromedriver.exe')
def login(self):
self.driver.get('https://smartrevise.online/')
sleep(2)
# Optional - removes the cookies pop up that blocks the login element on the page
cookie_button = self.driver.find_element_by_xpath('/html/body/div[1]/div/a')
cookie_button.click()
# Change 1 - xpath updated to target new login button on page
fb_btn = self.driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div/a')
fb_btn.click()
email_in = self.driver.find_element_by_xpath('//*[@id="Email"]')
email_in.send_keys(username)
pw_in = self.driver.find_element_by_xpath('//*[@id="Password"]')
pw_in.send_keys(password)
# Change 2 - xpath updated to target the login button after credentials changed
login_btn = self.driver.find_element_by_xpath(
'/html/body/div[4]/div/div/div/div/div[2]/div/div/div/form/div[3]/div[2]/button')
login_btn.click()
def course(self):
# Change 3 - xpath updated to target course select button on page again, which has changed location
c_btn = self.driver.find_element_by_xpath(
'/html/body/div[2]/div/div/div[2]/div[3]/div[2]/div/div/div[2]/div/div/div/div/a/div')
c_btn.click()
def checkNone(self):
n_btn = self.driver.find_element_by_xpath('//*[@id="tf-selectnone"]')
n_btn.click()
update_btn = self.driver.find_element_by_xpath('//*[@id="topicfilterform"]/div/div[3]/input')
update_btn.click()
def checkAll(self):
n_btn = self.driver.find_element_by_xpath('//*[@id="tf-selectall"]')
n_btn.click()
update_btn = self.driver.find_element_by_xpath('//*[@id="topicfilterform"]/div/div[3]/input')
update_btn.click()
def clickStart(self):
# Change 4 - updated xpath to press quiz button correctly
s_btn = self.driver.find_element_by_xpath(
'/html/body/div[2]/div/div/div[2]/div[2]/div/div[2]/div[1]/div[1]/div/a/div')
s_btn.click()
# Change 6 - Added new line to press start of the quiz with updated xpath
s_btn = self.driver.find_element_by_xpath(
'/html/body/div[2]/div/div/div[2]/div[2]/div/div[2]/div[2]/div/div/div[2]/a')
s_btn.click()
def idk(self):
idk_btn = self.driver.find_element_by_xpath('//*[@id="answercontainer"]/div[5]/a')
idk_btn.click()
def randomO(self):
o = randint(1, 4)
oC_btn = self.driver.find_element_by_xpath(f'//*[@id="answercontainer"]/div[3]/a')
oC_btn.click()
def next(self):
try:
n_btn = self.driver.find_element_by_xpath('//*[@id="lnkNext"]')
n_btn.click()
except:
n2_btn = self.driver.find_element_by_xpath('/html/body/div/div[1]/div[1]/div[3]/div')
n2_btn.click()
def logQ(self):
q_elem = self.driver.find_element_by_xpath('//*[@id="questiontext"]')
q = q_elem.text
print(q)
o1_elem = self.driver.find_element_by_xpath('//*[@id="answercontainer"]/div[1]/a')
o1 = o1_elem.text
print(o1)
o2_elem = self.driver.find_element_by_xpath('//*[@id="answercontainer"]/div[2]/a')
o2 = o2_elem.text
print(o2)
o3_elem = self.driver.find_element_by_xpath('//*[@id="answercontainer"]/div[3]/a')
o3 = o3_elem.text
print(o3)
o4_elem = self.driver.find_element_by_xpath('//*[@id="answercontainer"]/div[4]/a')
o4 = o4_elem.text
print(o4)
with open('answers.csv', 'r', newline='') as f:
reader = csv.reader(f, delimiter=',')
inF = False
for row in reader:
if q in row[0] and (o1 in row[1] or o2 in row[1] or o3 in row[1] or o4 in row[1]):
print("Already in file")
r = row
inF = True
break
if inF is True:
if r[1] == o1:
o1_elem.click()
if r[1] == o2:
o2_elem.click()
if r[1] == o3:
o3_elem.click()
if r[1] == o4:
o4_elem.click()
else:
print("aaaaaa")
correct = int(input("Correct Option: "))
arr = [o1, o2, o3, o4]
correctAnsIndex = correct-1
correctAns = arr[correctAnsIndex]
arrBtn = [o1_elem, o2_elem, o3_elem, o4_elem]
arrBtn[correctAnsIndex].click()
aC = input("Was it correct? ").upper()[0]
if aC == "Y":
with open('answers.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([q, correctAns])
else:
aCA = int(input("What is the correct answer? "))
with open('answers.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([q, arr[aCA]])
bot = ReviseBot()
bot.login()
bot.course()
# bot.checkAll()
bot.clickStart()
while True:
sleep(3)
bot.logQ()
sleep(1)
bot.next()