From d3803fb0dc887f8a98311379e89cf12c0e60162e Mon Sep 17 00:00:00 2001 From: Luc Mcgrady Date: Sun, 23 Jul 2023 13:16:58 +0100 Subject: [PATCH 1/2] Added: Wildcard support --- README.md | 2 -- package/fsrs4anki_optimizer/__main__.py | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f273c5d..170a68c 100644 --- a/README.md +++ b/README.md @@ -166,8 +166,6 @@ options: -o OUT, --out OUT File to APPEND the automatically generated profile to. ``` -Please note that this does not support multiple files in one command / wildcards so for that functionality use a for loop. - #### Expected Functionality: ![image](https://github.com/Luc-mcgrady/fsrs4anki/assets/63685643/ac2e8ae0-726c-46fd-b110-0701fa87cb66) diff --git a/package/fsrs4anki_optimizer/__main__.py b/package/fsrs4anki_optimizer/__main__.py index 6f15d87..3340837 100644 --- a/package/fsrs4anki_optimizer/__main__.py +++ b/package/fsrs4anki_optimizer/__main__.py @@ -1,4 +1,3 @@ -# python fsrs4anki_optimizer_cmd.py import fsrs4anki_optimizer import argparse import json @@ -86,7 +85,7 @@ def remembered_fallback_prompt(key: str, pretty: str = None): profile = \ f"""{{ // Generated, Optimized anki deck settings - "deckName": "{args.filename}",// PLEASE CHANGE THIS TO THE DECKS PROPER NAME + "deckName": "{filename}",// PLEASE CHANGE THIS TO THE DECKS PROPER NAME "w": {optimizer.w}, "requestRetention": {optimizer.optimal_retention}, "maximumInterval": 36500, @@ -112,7 +111,7 @@ def remembered_fallback_prompt(key: str, pretty: str = None): config_save = os.path.expanduser(".fsrs4anki_optimizer") parser = argparse.ArgumentParser() - parser.add_argument("filename") + parser.add_argument("filenames", nargs='+') parser.add_argument("-y","--yes", action=argparse.BooleanOptionalAction, help="If set automatically defaults on all stdin settings." @@ -122,13 +121,12 @@ def remembered_fallback_prompt(key: str, pretty: str = None): ) args = parser.parse_args() - - if os.path.isdir(args.filename): - files = [f for f in os.listdir(args.filename) if f.lower().endswith('.apkg')] - files = [os.path.join(args.filename, f) for f in files] - for file_path in files: - args.filename = file_path - process(file_path) - else: - process(args.filename) + for filename in args.filenames: + if os.path.isdir(filename): + files = [f for f in os.listdir(args.filename) if f.lower().endswith('.apkg')] + files = [os.path.join(filename, f) for f in files] + for file_path in files: + process(file_path) + else: + process(filename) From 44898d2c6577dae7b4bb27b5331008647fbb116b Mon Sep 17 00:00:00 2001 From: Luc Mcgrady Date: Sun, 23 Jul 2023 15:17:47 +0100 Subject: [PATCH 2/2] Fix: forgot to change variable name --- package/fsrs4anki_optimizer/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/fsrs4anki_optimizer/__main__.py b/package/fsrs4anki_optimizer/__main__.py index 3340837..e276a28 100644 --- a/package/fsrs4anki_optimizer/__main__.py +++ b/package/fsrs4anki_optimizer/__main__.py @@ -123,7 +123,7 @@ def remembered_fallback_prompt(key: str, pretty: str = None): for filename in args.filenames: if os.path.isdir(filename): - files = [f for f in os.listdir(args.filename) if f.lower().endswith('.apkg')] + files = [f for f in os.listdir(filename) if f.lower().endswith('.apkg')] files = [os.path.join(filename, f) for f in files] for file_path in files: process(file_path)