Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wildcard support #381

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 10 additions & 12 deletions package/fsrs4anki_optimizer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# python fsrs4anki_optimizer_cmd.py <filename.apkg|filename.colpkg>
import fsrs4anki_optimizer
import argparse
import json
Expand Down Expand Up @@ -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,
Expand All @@ -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."
Expand All @@ -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(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)