forked from Gwyd0/Sparx-bwk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGecko_SPARXBWK.py
158 lines (128 loc) · 5.72 KB
/
Gecko_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
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 info:
USERNAME = ""
PASSWORD = ""
PATH = 'chromedriver.exe' # path to chromedriver
VERSION = '1.3 - Gecko'
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)
try:
f = open("Logs/Log_{0}.txt".format(FILE_NAME), "a")
f.write("{0} {1} \n".format(str(current_time), str(message)))
f.close()
except:
log("[ERROR] 3 - Failed to log")
print(current_time + message)
info.lastmsg = message
return
def savesettings():
info.USERNAME = input("[SETTINGS] Please enter your sparx username: ")
info.PASSWORD = input("[SETTINGS] Please enter your sparx password: ")
INPUT1 = input("[SETTINGS] Do You want Autocontinue On? (skips games): ").casefold()
INPUT2 = input("[SETTINGS] Do You want Autobwk On? (Does Bookwork CODES may fail): ").casefold()
INPUT3 = input("[SETTINGS] Save Settings?: ").casefold()
if INPUT1 == "true" or INPUT1 == "yes":
info.autocontinue = True
print("[SETTINGS] autocontinue enabled")
if INPUT2 == "true" or INPUT2 == "yes":
info.autobwk = True
print("[SETTINGS] autobwk enabled")
if INPUT3 == "true" or INPUT3 == "yes":
print("[SETTINGS] 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("[Error] Invalid argument")
exit()
def loadsettings():
try:
with open('Logs/settings.json') as json_file:
data = json.load(json_file)
print("[SETTINGS] 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("[LOG] Writing New Log")
log("[LOG] New Log Made [NAME] " + FILE_NAME)
return
except:
log("[ERROR] 2 - FAILED TO WRITE LOG")
return
def start():
print("By Gwyd0 VERSION." + info.VERSION)
if not loadsettings(): # if loadsettings returns false then savesettings for next time.
savesettings()
makelogfile()
DRIVER = webdriver.Firefox()
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("[MAIN] Firefox Version: " + str(DRIVER.capabilities['browserVersion']))
log("[MAIN] If Firefox fails to open. install the newest version of geckodriver.")
try:
mainloop(DRIVER)
except:
log("[MAIN] Firefox Closed. Exiting.")
info.isopen = False
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()