kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
1.99k stars 150 forks source link

Set SRS mastery data #11

Open holocronweaver opened 7 years ago

holocronweaver commented 7 years ago

I am using genanki to convert data from an SRS app to Anki. I want to translate the SRS mastery data so the Anki items are due roughly when they would have been in the original SRS app.

How can I accomplish this using genanki?

Near as I can tell the fields in Card.write_to_db control this, but I am not sure what the SRS-related fields mean. I guess I will have to look at the Anki source to figure it out. AnkiDroid has some convenient documentation.

I would prefer to set SRS data at the Note level.

I plan to implement this feature, but thought I would ask for some guidance first.

holocronweaver commented 7 years ago

Further, I would like to customize deck settings, such as learning intervals. If we have a dict of default deck values which can be user customized, then we can simply do APKG_COL.format(values).

kerrickstaley commented 7 years ago

Re: the SRS progress data, please add due, ivl, factor, reps, etc. as properties of Card (I'm actually not super familiar with how these affect the SRS algorithm/which fields are relevant). Make them keyword args to init that default to 0, and update Card.write_to_db to use them.

Then, when you instantiate your Note, you can iterate over your_note.cards and update the fields appropriately. You may want to add higher-level helper functions like set_suspended to make it easier to do certain things.

Re: deck settings, feel free to send a PR, I'm also not very familiar with how they work. In general to figure these things out you have to create a dummy deck in the Anki desktop app, tweak the settings you care about, then export it to an apkg, unzip it, and inspect the collection.anki2 file with sqlite. Also don't call .format on APKG_COL, use prepared statements instead (example https://github.com/kerrickstaley/genanki/commit/8ab8549e76a65337547a188028b3727a423e72d9).