Initial commit
This commit is contained in:
24
flashcards/decks.py
Normal file
24
flashcards/decks.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from flashcards.models import simple
|
||||
from flashcards.random import random_anki_identifier
|
||||
from flashcards.config import config
|
||||
import genanki
|
||||
|
||||
|
||||
|
||||
def create_deck(notes, deck_name, deck_fname):
|
||||
# Create anki deck
|
||||
deck = genanki.Deck(
|
||||
random_anki_identifier(),
|
||||
deck_name)
|
||||
|
||||
# Add notes to deck
|
||||
for front, back in notes:
|
||||
note = genanki.Note(
|
||||
model=simple,
|
||||
fields=[front, back])
|
||||
deck.add_note(note)
|
||||
|
||||
# Write deck to file
|
||||
out_path = config.decks_dir / f'{deck_name}.apkg'
|
||||
print(f'Writing to {out_path}')
|
||||
genanki.Package(deck).write_to_file(out_path)
|
||||
Reference in New Issue
Block a user