forked from Gwyd0/Sparx-bwk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChrome_SPARXBWK.py
174 lines (144 loc) · 6.38 KB
/
Chrome_SPARXBWK.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from datetime import datetime
import time
import json
FILE_NAME = datetime.now().strftime("%d-%m-%Y-%H-%M-%S")
CODES = []
class bcolors:
# stolen from blender build script lmaoo
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class tags:
error = bcolors.FAIL + "[ERROR] " + bcolors.ENDC
main = bcolors.HEADER + "[MAIN] " + bcolors.ENDC
log = "[LOG] "
settings = "[SETTINGS] "
class info:
USERNAME = ""
PASSWORD = ""
PATH = 'chromedriver.exe' # path to chromedriver
VERSION = '1.4 - Chrome - Win64'
lastmsg = ""
isopen = True
autocontinue = False
autobwk = False
def log(message):
if info.lastmsg == message or len(message) < 34:
return
else:
t = time.localtime()
current_time = time.strftime("%H:%M:%S ", t)
f = open("Logs/Log_{0}.txt".format(FILE_NAME), "a")
f.write("{0} {1} \n".format(str(current_time), str(message)))
f.close()
print(current_time + message)
info.lastmsg = message
return
def savesettings():
info.USERNAME = input(tags.log + "Please enter your sparx username: ")
info.PASSWORD = input(tags.log + "Please enter your sparx password: ")
INPUT1 = input(tags.log + "Do You want Autocontinue On? (skips games): ").casefold()
INPUT2 = input(tags.log + "Do You want Autobwk On? (Does Bookwork CODES may fail): ").casefold()
INPUT3 = input(tags.log + "Save Settings?: ").casefold()
if INPUT1 == "true" or INPUT1 == "yes":
info.autocontinue = True
print(tags.log + "autocontinue enabled")
if INPUT2 == "true" or INPUT2 == "yes":
info.autobwk = True
print(tags.log + "autobwk enabled")
if INPUT3 == "true" or INPUT3 == "yes":
print(tags.log + "saving settings. This may take some time")
data = {'settings': [
{'USERNAME': info.USERNAME, 'PASSWORD': info.PASSWORD, 'acon': info.autocontinue, 'abwk': info.autobwk}]}
with open('Logs/settings.json', 'w') as outfile:
json.dump(data, outfile)
return
else:
print(tags.error + "Invalid argument")
info.isopen = False
return
def loadsettings():
try:
with open('Logs/settings.json') as json_file:
data = json.load(json_file)
print(tags.log + "Loading settings. This may take some time")
info.USERNAME = data['settings'][0]['USERNAME']
info.PASSWORD = data['settings'][0]['PASSWORD']
info.autocontinue = data['settings'][0]['acon']
info.autobwk = data['settings'][0]['abwk']
return True
except:
return False
def makelogfile():
try:
f = open("Logs/Log_{0}.txt".format(FILE_NAME), "a")
f.write(
"[SPARX BWK LOGS]\n[START TIME] {0}\n--- [SETTINGS] --- \n[USER] {1}\n[PASSWORD] {2}\n["
"AUTOCONTINUE] {3}\n[AUTOBWC] {4}\n[VERSION] {5}\n--- [WORK LOGS] --- \n".format(
FILE_NAME, info.USERNAME, info.PASSWORD, str(info.autocontinue), str(info.autobwk), info.VERSION))
f.close()
log(tags.log + "Writing New Log")
log(tags.log + "New Log Made [NAME] " + FILE_NAME)
return
except:
log(tags.error + "FAILED TO WRITE LOG")
return
def start():
print(bcolors.OKBLUE + "By Gwyd0 VERSION." + info.VERSION + bcolors.ENDC)
if not loadsettings(): # if loadsettings returns false then savesettings for next time.
savesettings()
makelogfile()
log(tags.main + "If Chrome fails to open. Install the newest version of Chromedriver.")
DRIVER = webdriver.Chrome(info.PATH)
DRIVER.get(
"https://auth.sparxmaths.uk/oauth2/auth?client_id=sparx-maths-sw&hd=ad6ebaa5-6e59-4e31-9840-d14daad3bf03&redirect_uri=https%3A%2F%2Fstudentapi.api.sparxmaths.uk%2Foauth%2Fcallback&response_type=code&scope=openid+profile+email&state=aEeScyZU4UJbK7UwJ9lVwQRFTPfTAQDFPqgngzPBR2GMxzlTw0lrajfG85yGLaCKyB0bOQxuLDCSSoccNiDnHdNkkAvbL6zYMc21Q8UOMAILV60eRzCmAkI5EuMxywmaxejArNkS4CK0l85omVBvDjBXpJMbNlTb0j6UPajHd4z8EnpTXmC6jD-KbDSLbU-ykoN_dt8k26joQJSq9dls8u4XczPi5RvfC81y8KNSIfxXDOjKdYgXuCObo1gYNUdPcww%3D")
USERNAME_ELEMENT = DRIVER.find_element(By.ID, "username")
PASSWORD_ELEMENT = DRIVER.find_element(By.ID, "password")
USERNAME_ELEMENT.send_keys(info.USERNAME)
PASSWORD_ELEMENT.send_keys(info.PASSWORD)
PASSWORD_ELEMENT.send_keys(Keys.RETURN)
log(tags.main + "Chrome Version: " + str(DRIVER.capabilities['browserVersion']))
print(bcolors.OKBLUE + "------------------ BOOKWORK CODES ------------------" + bcolors.ENDC)
try:
mainloop(DRIVER)
except:
print(bcolors.FAIL + "------------------ CHROME CLOSED ------------------" + bcolors.ENDC)
info.isopen = False
input(tags.error + "Exit to continue.")
exit()
def mainloop(driver):
while info.isopen:
if "Sparx" in driver.title:
try:
BWK = driver.find_element(By.CLASS_NAME, 'bookwork-code')
try:
kp = driver.find_element(By.CLASS_NAME, 'number-input')
if kp.get_attribute("value") != "":
log("[BWK] " + BWK.text + " [ANSWER] " + kp.get_attribute("value"))
except:
d = 9
try:
sl = driver.find_element(By.CLASS_NAME, 'selected')
if sl.text != "" and not "answer" in sl.text:
log("[BWK] " + BWK.text + " [ANSWER] " + sl.text)
except:
if info.autocontinue:
a = driver.find_element(By.CLASS_NAME, "button-text")
b = driver.find_element(By.CLASS_NAME, "button-text")
if a.text == "Continue" or a.text == "Second chance":
a.click()
elif b.text == "Continue":
b.click()
except:
d = 1
if __name__ == '__main__':
start()