-
Notifications
You must be signed in to change notification settings - Fork 1
/
drill-to-quizlet.py
46 lines (35 loc) · 1.17 KB
/
drill-to-quizlet.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
import json
def json_to_dict(file_name):
with open(file_name, 'r') as f:
questions_dict = json.load(f)
return questions_dict
def save_file(file_name, contents):
f = open(file_name, "w+")
f.write(contents)
f.close()
def parse_drill_dict(questions_dict):
TERM_DELIMITER = ";;;"
CARD_DELIMITER = "\n\n\n"
result = ""
for question in questions_dict:
right = ""
curr_char = "a"
result += "*" + question['name'] + "*\n"
for answer in question['answers']:
curr_answer = curr_char + ") " + answer['body']
result += curr_answer + "\n"
if answer['right']:
right = curr_answer
curr_char = chr(ord(curr_char) + 1)
result += TERM_DELIMITER + right + CARD_DELIMITER
return result
def drill_to_quizlet_file(file_name):
json_dict = json_to_dict(file_name)
parsed_drill = parse_drill_dict(json_dict)
try:
new_name = file_name.split(".")[0]
except IndexError:
new_name = file_name
save_file(new_name + "-quizlet.txt", parsed_drill)
if __name__ == "__main__":
drill_to_quizlet_file("questions_PB151.json")