-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanki.py
62 lines (53 loc) · 1.5 KB
/
anki.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
import genanki
from template import front_template, back_template, style_template
def add_notes(deck, model, notes):
def note_constructor(fields):
# Note
return genanki.Note(
model=my_model,
fields=fields
)
for note in notes:
my_note = note_constructor(note)
deck.add_note(my_note)
def save_apkg(deck, filename):
genanki.Package(deck).write_to_file(filename)
# Model (Note type)
my_model = genanki.Model(
1261022550,
'Basic (lang)',
fields=[
{'name': 'Expression'},
{'name': 'IPA'},
{'name': 'Audio'},
{'name': 'Definition'},
{'name': 'Image'},
{'name': 'Collocation'},
{'name': 'Example sentence'},
{'name': 'Source'}
],
templates=[
{
'name': 'Card 1',
'qfmt': front_template,
'afmt': back_template,
},
],
css=style_template
)
# Deck
my_deck = genanki.Deck(
1547962859,
'English🇺🇸::Kindle'
)
if __name__ == "__main__":
notes = [
['expr_test1', 'no_ipa', 'no_audio',
'no_def', 'no_image', 'no_collocation', 'no_example', 'no_source'],
['expr_test2', 'no_ipa', 'no_audio',
'no_def', 'no_image', 'no_collocation', 'no_example', 'no_source'],
['expr_test3', 'no_ipa', 'no_audio',
'no_def', 'no_image', 'no_collocation', 'no_example', 'no_source']
]
add_notes(my_deck, my_model, notes)
save_apkg(my_deck, 'output.apkg')