Why my hook in code doesn't work?

Hey, I’m new to creating addons in Anki but I’m really well motivated to learn how to do that. My goal is to show a message box every time the reviewer finishes ansewring a card with a number of cards done on a given day. I don’t know why but my hook doesn’t work:

from aqt import mw
from aqt.utils import showInfo
from anki.hooks import addHook

def testFunction(reviewer, card, ease):

cardCount = int(mw.col.db.scalar("""SELECT strftime('%s','now',
'localtime', 'start of day');""")) * 1000
totalreviews = mw.col.db.scalar("select count(id) from revlog where id >= %d" % cardCount)

# show a message box
showInfo("Card count: %s" % totalreviews)

addHook(“reviewer_did_answer_card”, testFunction)

reviewer_did_answer_card is a new-style hook, so I think you should use gui_hooks instead of addHook.
Try something like this:

from aqt import gui_hooks
gui_hooks.reviewer_did_answer_card.append(testFunction)
4 Likes