Simple add-on: flag cards with x lapses

Not big on coding. Tried to use ChatGPT for this. Any idea why it does not work? I get the dialog box but cards don’t get flagged.

from aqt import mw
from aqt import gui_hooks
from aqt.utils import showInfo
from anki.cards import Card


def flag_hard_cards(reviewer, card: Card, ease: int):
    if ease == 1:  # Lapse occurs when ease is 1 (when the answer is marked incorrect)
        card.load()
        if card.lapses >= 5 and card.user_flag != 2:  # Check if lapses are >= 5 and card doesn't already have a red flag
            card.user_flag = 2 # Red flag
            card.flush()
            showInfo(f"The card has been flagged red because it has been lapsed {card.lapses} times.")

gui_hooks.reviewer_did_answer_card.append(flag_hard_cards)

Hi,
card.user_flag is only used the get the current flag. To set the flag to 2 you use card.set_user_flag(2)

Also, the 2 flag is the orange one. 1 is red.

3 Likes

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