diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-10-08 14:34:00 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-10-08 14:34:00 +0200 |
commit | 1cf671c61981442b76c575e944bc132f514cf7a5 (patch) | |
tree | 6b10677b7f55c3a45406afb381128c64d2ecd301 /bulk-audio/bulk-audio.py | |
parent | 7e0166543e946a7e7a553169a49420e769a53e14 (diff) |
add anki search query filtering to bulk-audio3.6.0
Diffstat (limited to 'bulk-audio/bulk-audio.py')
-rwxr-xr-x | bulk-audio/bulk-audio.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/bulk-audio/bulk-audio.py b/bulk-audio/bulk-audio.py index 1027b3e..1fa84bb 100755 --- a/bulk-audio/bulk-audio.py +++ b/bulk-audio/bulk-audio.py @@ -48,6 +48,7 @@ def parse_args(argv): parser.add_argument("-n", "--noaudio", help="only modify notes that have \"noaudio\" as AUDIO_FIELD value", action='store_true') parser.add_argument("-i", "--note-id", help="select specific note (specify multiple times to select multiple notes)", action='append', nargs=1, default=[]) parser.add_argument("-d", "--dry-run", help="print only, do not edit anything", action='store_true') + parser.add_argument("-q", "--query", help="filter notes by search query", default=None) return parser.parse_known_args(argv[1:]) def main(): @@ -65,6 +66,7 @@ def main(): sys.stdout = real_stdout if aqt.mw == None: print("Please close any open Anki windows before running this script!") + sys.stdout = trash_out exit(1) # load last open profile if no profile was specified on command line (option parsed by Anki) @@ -85,8 +87,14 @@ def main(): if options.noaudio: note_ids = [nid for nid in note_ids if col.get_note(nid)[options.audio_field] == "noaudio"] + # filter flagged notes + if options.query != None: + filtered_note_ids = col.find_notes(options.query) + note_ids = [nid for nid in note_ids if nid in filtered_note_ids] + if len(note_ids) == 0: print("-- No notes found! (check your filters or note type?) --") + sys.stdout = trash_out exit(1) edited_notes = 0 |