Skip to content

Instantly share code, notes, and snippets.

@jlumbroso
Created September 23, 2018 14:23
Show Gist options
  • Save jlumbroso/e17abff02d89be04240072191af09ab2 to your computer and use it in GitHub Desktop.
Save jlumbroso/e17abff02d89be04240072191af09ab2 to your computer and use it in GitHub Desktop.
Minimal example of how to create a working Anki deck with a media file embedded.
import genanki
my_model = genanki.Model(
1380120064,
'Example',
fields=[
{'name': 'Object'},
{'name': 'Image'},
],
templates=[
{
'name': 'Card 1',
'qfmt': '{{Object}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Image}}',
},
])
my_note = genanki.Note(
model=my_model,
fields=['JPEG File', '<img src="format.jpg" />'])
my_deck = genanki.Deck(
2059400191,
'Example')
my_deck.add_note(my_note)
my_package = genanki.Package(my_deck)
my_package.media_files = ['format.jpg']
my_package.write_to_file('output.apkg')
@unlocked2412
Copy link

Thank you so much for the example, @jlumbroso ! However, I am getting "format.jpg" doesn't exist. Where did you place that file ? In the root of your drive ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment