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.