Created
February 10, 2018 19:16
-
-
Save SecondReality/12083c7be65e33e4b1d39b7de8963d40 to your computer and use it in GitHub Desktop.
Exports a list of suspended cards from Anki, and re-suspends them in another deck
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
from aqt import mw | |
from aqt.utils import showInfo | |
from aqt.qt import * | |
import json | |
def exportSuspendedCards(): | |
cards = mw.col.findCards("\"deck:KKLC No Audio\"") | |
showInfo("Card count: %d" % len(cards)) | |
suspended=[] | |
for id in cards: | |
card = mw.col.getCard(id) | |
if card.queue == -1: | |
suspended.append(card.note()["Front"]) | |
with open('suspended.txt', 'w') as outfile: | |
json.dump(suspended, outfile) | |
def importSuspendedCards(): | |
toSuspend = [] | |
with open('C:\\Users\\{}\\AppData\\Roaming\\Anki2\\Vocab\\collection.media\\suspended.txt', 'r') as infile: | |
toSuspend = json.load(infile) | |
showInfo("Card count to suspend: %d" % len(toSuspend)) | |
showInfo("Example card: " + toSuspend[10]) | |
cards = mw.col.findCards("\"deck:Kodansha Kanji Learner's Course\"") | |
showInfo("Card count: %d" % len(cards)) | |
suspendSet = set(toSuspend) | |
suspendCount = 0 | |
idsToSuspend = [] | |
kanjiToSuspend = "" | |
for id in cards: | |
card = mw.col.getCard(id) | |
if card.note()["Kanji"] in toSuspend: | |
suspendCount=suspendCount+1 | |
idsToSuspend.append(id) | |
kanjiToSuspend = kanjiToSuspend + "\r\n" + card.note()["Kanji"] | |
showInfo("To suspend count final: %d" % suspendCount) | |
showInfo(kanjiToSuspend) | |
mw.col.sched.suspendCards(idsToSuspend) | |
#showInfo(json.dumps(cardo)) | |
#keys = mw.col.getCard(cards[0]) | |
#keys = keys.note().keys() | |
# showInfo("Keys: "+json.dumps(keys)) | |
# showInfo("VAL: " + mw.col.getCard(cards[0]).note()["Kanji"]) | |
action = QAction("Export Suspended Cards", mw) | |
action.triggered.connect(exportSuspendedCards) | |
mw.form.menuTools.addAction(action) | |
action = QAction("Import Suspended Cards", mw) | |
action.triggered.connect(importSuspendedCards) | |
mw.form.menuTools.addAction(action) | |
#card = mw.col.getCard(cardo[0]) | |
#mw.col.sched.suspendCards([cardo[0]]) | |
#mw.col.sched.suspendCards([cardo[1]]) | |
# get the number of cards in the current collection, which is stored in | |
# the main window | |
#did = mw.col.decks.id("ImportDecko").cardCount() | |
#mw.col.decks.select(did) | |
#cardCount = mw.col.decks.current() | |
#cardCount = mw.col.cardCount() | |
# show a message box | |
#showInfo(json.dumps(cardCount)) | |
#showInfo("Card count: %d" % len(cardCount)) | |
#keys = mw.col.getCard(cards[0]) | |
#keys = keys.note().keys() | |
#showInfo("Keys: "+json.dumps(keys)) | |
#showInfo("VAL: " + mw.col.getCard(cards[0]).note()["Kanji"]) | |
#for id in cards: | |
#card = mw.col.getCard(id) | |
#question = card.q() | |
#answer = card.a() | |
#if card.queue == -1: | |
#showInfo("Found a suspended card!") | |
#showInfo(json.dumps(cardo)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment