Skip to content

Instantly share code, notes, and snippets.

@kelciour
Created September 13, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelciour/9a6d173ab7589503e9776a327c863623 to your computer and use it in GitHub Desktop.
Save kelciour/9a6d173ab7589503e9776a327c863623 to your computer and use it in GitHub Desktop.
(debug console) convert tags to subdecks
import re
cnt = 0
nids = mw.col.findNotes("""
"deck:uTalk GCSE Italian"
""".strip())
for nid in nids:
note = mw.col.getNote(nid)
deck = mw.col.decks.get(note.cards()[0].did)
tags = note['Topic'].split('::')
subdecks = '::'.join(tags[1:])
subdecks = subdecks.replace('_', ' ')
deckname = "{}::{}".format(deck['name'], subdecks)
did = mw.col.decks.id(deckname)
cids = [c.id for c in note.cards()]
mw.col.decks.setDeck(cids, did)
note.flush()
cnt += 1
mw.reset()
print('Found {} notes.'.format(len(nids)))
print('Updated {} notes.'.format(cnt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment