-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine2deck.py
43 lines (29 loc) · 1.3 KB
/
combine2deck.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
import json
import os
# ==================================================================================================
filepath = os.path.dirname(os.path.realpath(__file__)) + "/"
notes_file = filepath + "sourcedata/notes.json"
strokes_file = filepath + "sourcedata/strokes.json"
audios_file = filepath + "sourcedata/audios.json"
deck_template = filepath + "deck.template.json"
outfile = filepath + "Anki-HanyuShuipingKaoshi.json"
# ==================================================================================================
def main():
with open(notes_file, "r", encoding="utf-8") as file:
notes = json.load(file)
with open(strokes_file, "r", encoding="utf-8") as file:
strokes = json.load(file)
with open(audios_file, "r", encoding="utf-8") as file:
audios = json.load(file)
with open(deck_template, "r", encoding="utf-8") as file:
deck = json.load(file)
media = list(strokes)
media.extend(audios)
deck["media_files"] = media
deck["notes"] = notes
with open(outfile, "w+", encoding="utf-8") as file:
json.dump(deck, file, ensure_ascii=False, indent=2, sort_keys=True)
# ==================================================================================================
if __name__ == "__main__":
main()
print("FINISHED")