Guest User

Untitled

a guest
Feb 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. from aqt import mw
  2. from aqt.utils import showInfo
  3. from aqt.qt import *
  4.  
  5. import json
  6.  
  7. def exportSuspendedCards():
  8. cards = mw.col.findCards("\"deck:KKLC No Audio\"")
  9. showInfo("Card count: %d" % len(cards))
  10.  
  11. suspended=[]
  12.  
  13. for id in cards:
  14. card = mw.col.getCard(id)
  15. if card.queue == -1:
  16. suspended.append(card.note()["Front"])
  17. with open('suspended.txt', 'w') as outfile:
  18. json.dump(suspended, outfile)
  19.  
  20. def importSuspendedCards():
  21. toSuspend = []
  22. with open('C:\\Users\\{}\\AppData\\Roaming\\Anki2\\Vocab\\collection.media\\suspended.txt', 'r') as infile:
  23. toSuspend = json.load(infile)
  24. showInfo("Card count to suspend: %d" % len(toSuspend))
  25. showInfo("Example card: " + toSuspend[10])
  26.  
  27. cards = mw.col.findCards("\"deck:Kodansha Kanji Learner's Course\"")
  28. showInfo("Card count: %d" % len(cards))
  29.  
  30. suspendSet = set(toSuspend)
  31. suspendCount = 0
  32. idsToSuspend = []
  33. kanjiToSuspend = ""
  34.  
  35. for id in cards:
  36. card = mw.col.getCard(id)
  37. if card.note()["Kanji"] in toSuspend:
  38. suspendCount=suspendCount+1
  39. idsToSuspend.append(id)
  40. kanjiToSuspend = kanjiToSuspend + "\r\n" + card.note()["Kanji"]
  41.  
  42. showInfo("To suspend count final: %d" % suspendCount)
  43. showInfo(kanjiToSuspend)
  44. mw.col.sched.suspendCards(idsToSuspend)
  45.  
  46. #showInfo(json.dumps(cardo))
  47.  
  48.  
  49. #keys = mw.col.getCard(cards[0])
  50. #keys = keys.note().keys()
  51. # showInfo("Keys: "+json.dumps(keys))
  52. # showInfo("VAL: " + mw.col.getCard(cards[0]).note()["Kanji"])
  53.  
  54.  
  55. action = QAction("Export Suspended Cards", mw)
  56. action.triggered.connect(exportSuspendedCards)
  57. mw.form.menuTools.addAction(action)
  58.  
  59. action = QAction("Import Suspended Cards", mw)
  60. action.triggered.connect(importSuspendedCards)
  61. mw.form.menuTools.addAction(action)
  62.  
  63.  
  64. #card = mw.col.getCard(cardo[0])
  65. #mw.col.sched.suspendCards([cardo[0]])
  66. #mw.col.sched.suspendCards([cardo[1]])
  67.  
  68.  
  69. # get the number of cards in the current collection, which is stored in
  70. # the main window
  71. #did = mw.col.decks.id("ImportDecko").cardCount()
  72. #mw.col.decks.select(did)
  73. #cardCount = mw.col.decks.current()
  74. #cardCount = mw.col.cardCount()
  75. # show a message box
  76. #showInfo(json.dumps(cardCount))
  77. #showInfo("Card count: %d" % len(cardCount))
  78.  
  79.  
  80.  
  81. #keys = mw.col.getCard(cards[0])
  82. #keys = keys.note().keys()
  83. #showInfo("Keys: "+json.dumps(keys))
  84. #showInfo("VAL: " + mw.col.getCard(cards[0]).note()["Kanji"])
  85.  
  86.  
  87. #for id in cards:
  88. #card = mw.col.getCard(id)
  89. #question = card.q()
  90. #answer = card.a()
  91. #if card.queue == -1:
  92. #showInfo("Found a suspended card!")
  93. #showInfo(json.dumps(cardo))
Add Comment
Please, Sign In to add comment