-
-
Save Destroxia54/6925a3e1cb75afc7a3dd14d1ba2ff611 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
# Updated for Windows Anki Distribution. Handles cases on Tags, and provides progress. | |
# TODO Need to pip install anki within your python path, can use cmd. "pip install anki" | |
import os | |
from typing import List | |
from anki.storage import Collection | |
import pdb | |
# the deck: https://ankiweb.net/shared/info/2072613354 | |
# TODO replace YOUR_USER_NAME | |
col = Collection(r'C:\Users\YOUR_USER_NAME\AppData\Roaming\Anki2\User 1\collection.anki2') # Use raw string (r'') | |
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 = None # Initialize typ as None to handle unexpected cases | |
for tag in tags: | |
tag_lower = tag.lower() # Normalize to lowercase for case-insensitive comparison | |
if 'level' in tag_lower: | |
level = tag | |
elif tag_lower == 'radical': | |
typ = 0 | |
elif tag_lower == 'kanji': | |
typ = 1 | |
elif tag_lower == '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)) | |
total_cards = len(cards) | |
for i, card_id in enumerate(cards): | |
if i % 10 == 0 or i == total_cards - 1: | |
print(f"Processing card {i+1}/{total_cards}...") | |
card = col.get_card(card_id) | |
card.due = i | |
col.update_card(card) | |
print("DONE!") | |
col.decks.save(deck) | |
col.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment