Created
February 17, 2023 02:53
-
-
Save BaksiLi/c6a371bf770e8dd8a2c703ae5087d31e to your computer and use it in GitHub Desktop.
Anki Python debug script to move "[sound:xxx]" between fields
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
, andPronunciation
, 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.