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 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)
        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
            showInfo(f"The card has been flagged red because it has been lapsed {card.lapses} times.")


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.


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