LLMs made me an addon to add subdecks

Previously when on SM2/v2/v3,
i use an addon that modify the interval, hope to also have “priority” as in supermemo.

seems not very working when anki updates (true for foss,
an update to fix a hole here make new holes there).

Due to self server and IOE (native) i am now updated,
at 23.10+FSRS.

others suggest me to tag the cards by lv1a, b, c;
lv2a, b, c etc and put on different decks that have different options,
each with different retention %.

making several “options” is easy,
but adding 3 - 6 subdecks is a time consuming work.

now we got LLMs,
i just asked GPT o1-preview (a GPT4?) to write me one.

it could add the subdecks easily. as a menu command.

image

Since i only have college 1 Sem (i.e. 6mo?) ANSI C/visual basic level,
i am dual licensing it (commercial and foss… GPL3?) and put the open source version here below.

hope someone may review it and see if the code is indeep danger,
pls alert me, thanks.

others may tweak it for their own use,
or, indeep could ask LLMs to do whatever you want and share like me too.

Richard stallman: everyone SHOULD be a programmer
Wang: everyone is NOW a programmer.

I beg you guys give LLMs a chance! To write addons!

1 Like

I put in another post to make it look cleaner

from aqt import mw
from aqt.qt import QAction, QInputDialog
from aqt.utils import showInfo
from anki.hooks import wrap
from anki.decks import DeckManager

def check_and_create_subdecks(deck_id, level):
    # Define the required subdeck names for each level
    if level == "lv1":
        subdeck_names = [
            "lv1a-lv1-pri-highest",
            "lv1b-pri-high",
            "lv1c-lv2a-lv2-pri-nml"
        ]
    elif level == "lv2":
        subdeck_names = [
            "lv1c-lv2a-lv2-pri-nml",
            "lv2b-pri-low",
            "lv2c-lv3-pri-lowest"
        ]
    else:
        showInfo("Invalid level selected.")
        return

    # Get the full name of the selected deck
    deck = mw.col.decks.get(deck_id)
    parent_deck_name = deck['name']

    # Get all existing deck names
    existing_decks = mw.col.decks.all_names()

    # Initialize a list to keep track of missing subdecks
    missing_subdecks = []

    # Check for each required subdeck
    for subdeck_name in subdeck_names:
        full_subdeck_name = f"{parent_deck_name}::{subdeck_name}"
        if full_subdeck_name not in existing_decks:
            # Create the missing subdeck
            mw.col.decks.id(full_subdeck_name)
            missing_subdecks.append(subdeck_name)

    if missing_subdecks:
        mw.col.reset()
        showInfo(f"The following subdecks were created under '{parent_deck_name}':\n" +
                 "\n".join(missing_subdecks))
    else:
        showInfo(f"All required subdecks for {level} already exist under '{parent_deck_name}'.")

def on_deck_selected():
    # Get the currently selected deck ID
    deck_id = mw.col.decks.current()['id']
    if not deck_id:
        showInfo("Please select a deck before running this add-on.")
        return

    # Prompt the user to select the level
    levels = ["lv1", "lv2"]
    level, ok = QInputDialog.getItem(mw, "Select Level", "Choose the level:", levels, 0, False)
    if ok and level:
        check_and_create_subdecks(deck_id, level)
    else:
        showInfo("Operation cancelled.")

def add_menu_option():
    action = QAction("Check and Create Subdecks", mw)
    action.triggered.connect(on_deck_selected)
    mw.form.menuTools.addAction(action)

add_menu_option()