-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
50 lines (38 loc) · 1.17 KB
/
build.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
import os
import yaml
import genanki
def dump(uid, name, fin, fout):
notes = []
anki_model = genanki.Model(
uid,
name,
fields = [
{'name': 'Question'},
{'name': 'Answer'},
],
templates = [
{
'name': 'Card Note',
'qfmt': '<strong>{{Question}}</strong>',
'afmt': '{{FrontSide}}<hr id="answer"><strong>{{Answer}}</strong>',
},
])
with open(fin, 'r') as f:
for line in f:
notes.append(tuple(line.strip().split(';', 1)))
anki_notes = [genanki.Note(
model = anki_model,
fields = [question, answer]
) for question, answer in notes]
anki_deck = genanki.Deck(uid, name)
for note in anki_notes:
anki_deck.add_note(note)
genanki.Package(anki_deck).write_to_file(fout)
pass
if __name__ == '__main__':
settings = []
with open('inputs.yaml', 'r') as file:
settings = yaml.load(file, Loader=yaml.FullLoader)
for deck in settings['data']:
print("Generating deck: ", deck['name'])
dump(deck['uid'], deck['name'], deck['input'], deck['output'])