In what hook would i modify the due of a card before adding it

Im making an addon to insert new cards at the top of the queue. I have no idea what im doing, but I managed to cobble together everything i need except the part where i modify the actual new cards

This is what i got so far

from aqt import mw, gui_hooks
from aqt.utils import showInfo, qconnect
from aqt.qt import *
from anki.collection import CARD_TYPE_NEW

insert_at_first = False

def getMinPosition() -> int:
    cardCount = mw.col.cardCount()
    assert mw
    assert mw.col.db

    min_position = mw.col.db.first(
        f"select min(due) from cards where type={CARD_TYPE_NEW} and odid=0"

    return min_position

def isInsertFirst(on) -> None:

    min = getMinPosition()
    on_text = "enabled" if on else "disabled"
    showInfo(f"Insert New Cards On Top is now {on_text}\n\nFirst position is {min}")

action = QAction(mw)
action.setText("Insert new cards on top")

Im looking at the hooks and i cant find a proper hook where i can access the card after or before being inserted

Ill keep looking, but a nudge on the right direction would be appreciated :slight_smile:

Okay i think the hook has to be gui_hooks.add_cards_did_add_note

I was trying to modify the card before inserting it but that doesnt seems possible with hooks

Now the only thing left is to figure out how to modify a card

I have seen reposition_new_cards from aqt.operations.scheduling. Still figuring out how to call it

Okay, i did it! It took me a while but it works now!

Ill publish it soon! and put a link here!


Okay! it gave me some error when i tried to upload it the other day and i didnt have time again until today!

I hope is useful to somebody else!