-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_beta1.1.0.py
256 lines (178 loc) · 7.58 KB
/
main_beta1.1.0.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/python3
import requests
import getpass
from bs4 import BeautifulSoup as bs
"""
TODO
--fix Listening Lab ++
--fix Vocab Academy
--add index finder
"""
#Try to Read EMAIL and PASSWORD
try:
file = open('login_info.data', 'r')
login_info_data= file.readlines()
email = login_info_data[0]
password = login_info_data[1]
file.close()
except(FileNotFoundError,IndexError):
email = input("email: ")
password = getpass.getpass("Password: ")
raw_data = [email,"\n", password]
file_new = open('login_info.data', 'w')
file_new.writelines(raw_data)
file_new.close()
# headers
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
# login data
login_data = {
'name': email,
'pass': password,
'form_id': 'user_login',
'op': 'Log+in'
}
with requests.Session() as s:
# Get Vocab answers function
def GetVocab():
# get vocab's source code
vocab_page= s.get(target_HW + "?step=vocab-academy")
vocab_page_content = bs(vocab_page.content, "html5lib")
# get script
vocab_script = vocab_page_content.find('p', {'class': 'mb-0'})
# get answer keys
vocab_answer = vocab_page_content.findAll('script', {'type': "text/javascript"})[1]
# print script and answers
print(vocab_script, '\n' * 3, vocab_answer)
# get Comprehension
def GetComp():
# get source code of comp page
comp_page = s.get(target_HW + "?step=comprehension")
comp_page_content = bs(comp_page.content, "html5lib")
#get answers as string
comp_answers = str(str(comp_page_content.findAll('script')[4]).split(""" is_correct_answer":"1" """))
#print answers
list_answer_end = []
for i in range(70,len(comp_answers)):
if(comp_answers[i] == "1" and comp_answers[i -10] == "_"):
list_answer_end.append(i - 24)
list_answer_end.reverse()
list_answer_string = []
str_answer = ""
for i in list_answer_end:
for h in range(i,70,-1):
if(comp_answers[h] == "\"" and i - h > 3):
list_answer_string.append(str_answer[::-1])
str_answer = ""
break
else:
str_answer = str_answer + comp_answers[h]
print(list(set(list_answer_string)))
# get Listening Lab
def ListLab():
#get source code of Listening Lab
listLab_page = s.get(target_HW + "?step=listening-lab")
listLab_page_content = bs(listLab_page.content, "html5lib")
#get answers
listLab_answers = str(str(listLab_page_content.findAll('script')[4]).split(""" is_correct_answer":"1" """))
#print(listLab_page_content.findAll('script')[4])
#print answers
list_answer_start = []
list_answer_end = []
list_answer_point = []
list_answer_end_clean_temp = []
list_answer_end_clean = []
for i in range(70,len(listLab_answers)):
if(listLab_answers[i] == "1" and listLab_answers[i -10] == "_"):
list_answer_point.append(i)
for g in list_answer_point:
x = 0
for h in range(g, g + 100):
if(listLab_answers[h] == "\""):
if(x == 7):
list_answer_start.append(h)
if(x == 8):
list_answer_end.append(h)
x += 1
for i in range(0, len(list_answer_start) -1):
list_answer_end_clean_temp.append(listLab_answers[list_answer_start[i]: list_answer_end[i]])
for h in list(set(list_answer_end_clean_temp)):
list_answer_end_clean.append(h)
print(list_answer_end_clean)
# get Advanced Comprehension
def AdvComp():
# get source AdvComp'scode
advComp_page = s.get(target_HW + "?step=advanced-comprehension")
advComp_page_content = bs(advComp_page.content, "html5lib")
# get answers
advCom_answers = str(str(advComp_page_content.findAll('script')[4]).split(""" is_correct_answer":"1" """))
#print answers
list_answer_end = []
for i in range(70,len(advCom_answers)):
if(advCom_answers[i] == "1" and advCom_answers[i -10] == "_"):
list_answer_end.append(i - 24)
list_answer_end.reverse()
list_answer_string = []
str_answer = ""
for i in list_answer_end:
for h in range(i,70,-1):
if(advCom_answers[h] == "\""):
list_answer_string.append(str_answer[::-1])
str_answer = ""
break
else:
str_answer = str_answer + advCom_answers[h]
print(list(set(list_answer_string)))
# get Grammar answers
def Gram():
#get source code
gram_page = s.get(target_HW + "?step=grammar")
gram_page_content = bs(gram_page.content, "html5lib")
#get answers
gram_answers = gram_page_content.findAll('script')[5]
# print answers
print(gram_answers)
# set login page
login_page = s.get("https://lingua-attack.com/en-EA/user/login", headers=headers)
# get login source code
login_page_content = bs(login_page.content, "html5lib")
# add form_build_id to login_data
login_data['form_build_id'] = login_page_content.find('input', attrs={'name': 'form_build_id'})['value']
# login
r = s.post("https://lingua-attack.com/en-EA/user/login", login_data, headers=headers)
try:
r.history[0].status_code
controlPoint0 = 1
except(IndexError):
print('Başarısız login çabası.')
file_delete = open('login_info.data', 'w+')
file_delete.close()
controlPoint0 = 0
# MAIN PART
target_HW = input("lingua homework link: ")
while(controlPoint0 == 1):
try:
# get vocab link
islem_no = int(input("Yapmak istediğin işlem ne?\nComprehension cevapları: 1\nListening Lab cevapları: 2\nAdvanced Comprehension cevapları: 3\nVocab Academy cevapları: 4\nGrammar cevapları: 5\nHomework Link Değiştir: 6\nYardımcı Notlar: 7\nÇıkış: 8\nİşlem No: "))
print("\n" * 3)
if(islem_no == 1):
GetComp();print("\n" * 3)
elif(islem_no == 2):
ListLab();print("\n" * 3)
elif(islem_no == 3):
AdvComp();print("\n" * 3)
elif(islem_no == 4):
GetVocab();print("\n" * 3)
elif(islem_no == 5):
Gram();print("\n" * 3)
elif(islem_no == 6):
target_HW = input("lingua homework link: ");print("\n" * 3)
elif(islem_no == 7):
print("""Başarılı olan/olamayan giriş bilgileriniz scripti tuttuğunuz uzantıda "login_info.data" dosyasında tutulmaktadır.\n\nBilgileri sıfırlamak için bu dosyayı silin.\n\nBu bilgiler şifrelenmemiştir, bu risk teşkil etmektedir.\n\nÖzellikle bu scripti paylaşırken "login_info.data" dosyasını paylaşmadığınıza emin olun.\n\n"login_info.data" scriptin gerekli bir parçası değildir, script kendi oluşturmaktadır ve giriş bilgilerinizi burada depolar. """, "\n" * 3)
elif(islem_no == 8):
break
else:
print("Geçerli bir işlem gir! ", "\n" * 3)
except:
print("Bir şeyleri yanlış yaptın!", "\n" * 3)