Answering a card programmatically

I’m wondering if it’s possible to answer a card without actually going to the review screen, and do it correctly. I know that I can call this: col.sched.answerCard(card, ease) but after playing with this function for a while I’ve noticed that it doesn’t behave as I expect it.

It always behaves as if the card was due at the time of each review, which is incorrect. All the reviews happened on the same day so the interval shouldn’t grow beyond 1 day.

How does this compare with filtered deck behaviour? If filtered decks affect the next due date differently then you might want to use that.

Yes, I’m thinking in this direction too. This approach is going to require more code though.

What’s needed:

  • create a temporary filtered deck.
  • move cards there.
  • grade them.
  • move the cards back to the original deck.
  • delete the filtered deck.

I found that col.sched.get_or_create_filtered_deck(deck_id=DeckId(0)) can be used to create a filtered deck but I don’t know what to do next. If I just call this function nothing happens.

Figured some things out. Correct me if they’re wrong.

  1. Call col.sched.get_or_create_filtered_deck(deck_id=DeckId(0)) and get a deck that doesn’t exist yet.
  2. Set settings, namely deck.config.search_terms and deck.config.reschedule = True
  3. Call col.sched.add_or_update_filtered_deck(deck) and get the deck’s id back.
  4. Answer cards in the deck by calling col.sched.answerCard()

After this the filtered deck has to be removed. This is where I’m currently stuck.

If I call col.decks.remove((deck_id,)) where deck_id is the ID I got from col.sched.add_or_update_filtered_deck(deck), it removes the deck with the cards in it.

Any update on this issue? Still having this same bug on latest version of Anki (Version ⁨24.04.1 (ccd9ca1a)⁩ Python 3.9.18 Qt 6.6.2 PyQt 6.6.1). I could not get the search term to work correctly either ( deck.config.search_terms is not settable, tried using temp_deck.config.SearchTerm.search = "" but that did not work either. But regardless, my filtered deck contained the card I was trying to review but it still left me with the same bugged dates.

Initially I created this topic because at Ajatt-Tools we needed the ability to grade cards from the Browser window. Eventually, we figured it out, and the new feature was added to AJT Card Management.

1 Like