Skip to content

Instantly share code, notes, and snippets.

@BaksiLi
Created February 17, 2023 02:53
Show Gist options
  • Save BaksiLi/c6a371bf770e8dd8a2c703ae5087d31e to your computer and use it in GitHub Desktop.
Save BaksiLi/c6a371bf770e8dd8a2c703ae5087d31e to your computer and use it in GitHub Desktop.
Anki Python debug script to move "[sound:xxx]" between fields
note_type = 'Basic'
regex = r'\[sound:.*\]'
field_from = 'Back'
field_to = 'Pronunciation'
model = mw.col.models.by_name(note_type)
notes = mw.col.models.nids(model)
for nid in notes:
note = mw.col.get_note(nid)
if m:=re.search(regex, note[field_from]):
# move sound string to field_to
note[field_to] = m.group(0)
# remove sound string from field_from
note[field_from] = re.sub(regex, '', note[field_from])
note.flush()
@BaksiLi
Copy link
Author

BaksiLi commented Feb 17, 2023

This script is designed to help users who are importing Anki decks, such as the Russian Core 100 deck, which do not use the built-in note types and can appear unappealing after import.

If you have your custom note types, such as a "Basic (+reverse)" type with fields for Front, Back, and Pronunciation, you can use this script to format the imported notes to fit your note type. To use the script, you first need to open the debug console in Anki and run the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment