Created
November 20, 2024 13:12
-
-
Save kiennguyen94/cb1a0a08477390b561ce2f967c7337c2 to your computer and use it in GitHub Desktop.
Script to sort the wanikani deck by level, radical, kanji, and vocab.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from typing import List | |
from anki.storage import Collection | |
# the deck: https://ankiweb.net/shared/info/2072613354 | |
# TODO replace YOUR_USER_NAME | |
col = Collection('/Users/{YOUR_USER_NAME}/Library/Application Support/Anki2/User 1/collection.anki2') | |
deck_id = col.decks.id('WaniKani') | |
deck = col.decks.get(deck_id) | |
cards = col.find_cards("deck:WaniKani") | |
def find_level(tags: List[str]): | |
level = "" | |
typ = 0 | |
for tag in tags: | |
if 'level' in tag: | |
level = tag | |
elif tag == 'radical': | |
typ = 0 | |
elif tag == 'kanji': | |
typ = 1 | |
elif tag == 'vocab': | |
typ = 2 | |
else: | |
raise RuntimeError("fu") | |
return level, typ | |
cards.sort(key= lambda card_id: find_level(col.get_card(card_id).note().tags)) | |
for i, card_id in enumerate(cards): | |
card = col.get_card(card_id) | |
card.due = i | |
col.update_card(card) | |
col.decks.save(deck) | |
col.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment