-
-
Save jlumbroso/e17abff02d89be04240072191af09ab2 to your computer and use it in GitHub Desktop.
| 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') |
Thanks!
What do I need to do to insert media dynamically, as an example, insert the mp3 file named as front side's word? The readme on genanki doesn't say how :(
Thanks for this, I was absolutely lost.
@mgnisia, @lowttl, @danpaldev, @chrisalbon β thanks so much for letting me know this was helpful! π€
@danpaldev: I am no expert, but as far as I know, that is not possible, the only thing that is possible is for you to batch generate the cards, such that you generate cards from a template that has the word on the front, and an MP3 of that word on the back. You would have to generate those cards, because AFAIK, Anki doesn't have any meta-programming features.
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 ?
@unlocked2412 It needs to be where you run the python script. Ideally, run the script from the same location as it is, and put the image there as well.
Thank you very much for the example π π