This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (52 loc) · 2.11 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
import json
import tkinter.messagebox as tm
import traceback
from requests import Session
from answer_handler import AnswerHandler
class InvalidLoginDetails(Exception):
pass
class LoginFrame():
def __init__(self):
print('Ensure that your google acount is NOT linked')
email = input('Email')
password = input('Password')
if '@' not in email:
email += '@utcportsmouth.org'
try:
Interface(email, password)
except InvalidLoginDetails as e:
print(e, file=sys.stderr)
class Interface:
def __init__(self, email, password):
self.session = Session()
self.test_login(email, password)
self.handler = AnswerHandler(self.session)
self.main_loop()
def main_loop(self):
print('Press ctrl-c to quit')
while True:
url = input('\nType Question url: ')
handler = AnswerHandler(self.session)
res, err = handler.answer_questions_V2(url)
if res:
print('No more questions for this URL')
else:
print(f'Unexpected exception occurred: {err}', file=sys.stderr)
traceback.print_exc()
def test_login(self, email, password):
login_url = 'https://www.drfrostmaths.com/process-login.php?url='
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/71.0.3578.98 Safari/537.36'}
data = {'login-email': email, 'login-password': password}
self.session.post(login_url, headers=headers, data=data)
try:
"""
verifying user is authenticated by tests if user can load the times tables
"""
res = self.session.get('https://www.drfrostmaths.com/homework/process-starttimestables.php')
json.loads(res.text)
except BaseException:
raise InvalidLoginDetails(f'Email: {email}, Password: {"*" * len(password)}')
if __name__ == "__main__":
lf = LoginFrame()
# wait for login to be retrieved