This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
forked from xiaorenwu241/FxxkSsxx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport.py
57 lines (47 loc) · 1.84 KB
/
export.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
#!/usr/bin/env python3
import hashlib
import bson
def ReadAnswerFromFile():
answer_file = open('ssxx.bson', 'rb')
answer_dictionary = bson.loads(answer_file.read())
answer_file.close()
print("已读取", len(answer_dictionary['hashBank'].items()), "个答案!")
print("learnt: ", len(answer_dictionary['questionBank'].items()))
return answer_dictionary
def SaveToFile(text):
export_file = open('ssxx_export.txt', 'w', encoding='utf-8')
export_file.write(text)
export_file.close()
print("已保存")
if __name__ == '__main__':
answer_dictionary = ReadAnswerFromFile()
question_bank = answer_dictionary['questionBank']
hash_bank = answer_dictionary['hashBank']
formatted_bank = []
for hash, question in question_bank.items():
question_title = question['title']
if not hash_bank.__contains__(hash):
print(question_title, "这道题居然没答案!!")
continue
right_answer_hash_arr = hash_bank[hash]
answer_arr = []
for option in question['options']:
code = option['code']
option_title = option['title']
option_hash = hashlib.md5(
option_title.encode(encoding='UTF-8')).hexdigest()
answer_arr.append(
(code, option_title, option_hash in right_answer_hash_arr))
formatted_bank.append((question_title, answer_arr))
print("已解析", len(formatted_bank), "个题目")
text = ""
for question_title, answer_arr in formatted_bank:
question_text = question_title + '\n'
for answer in answer_arr:
code, title, correct = answer
mark = '❌'
if correct:
mark = '✔️'
question_text += code + '. ' + title + ' ' + mark + '\n'
text += question_text + '\n'
SaveToFile(text)