Set card interval using Python

I’m starting to write a Python module to import notes from a CSV file along with scheduling data. I managed figure out how to create new cards and how to set their due date, but I can’t set the card’s interval. It seems like the interval gets overriden with the interval from the the current day to the due date when the collection is saved. Here’s my code:

from anki import collection

col = collection.Collection(‘/home/felipe/.local/share/Anki2/fromcsv01/collection.anki2’)
basic = col.models.by_name(‘Basic’)
note = col.new_note(basic)
note[‘Front’] = ‘This is the front of the card’
note[‘Back’] = ‘This is the back of the card’
deck = col.decks.by_name(‘my deck’)
col.add_note(note, deck[‘id’])

card =[0]
col.sched.set_due_date([], ‘365’)
card.ivl = 30
print(card.ivl) # outputs 30, as expected

card = col.get_card(
print(card.ivl) # outputs 365, I would hope for it to be 30

Is there any way around this?

I’m trying to avoid messing with the db directly, because I far as I understand its structure may change without notice in the future.

Simplest option: use ‘365!’ and give the card a year’s interval, so that if you remember it after a year you don’t end up repeating it unnecessarily. Second simplest is doing 30! and then 365. Updating card.ivl is basically updating the db directly, and if you go down that path you’ll to .flush() or update_card() the changes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.