Skip to content

Commit

Permalink
Add wildcard support (#381)
Browse files Browse the repository at this point in the history
* Added: Wildcard support

* Fix: forgot to change variable name
  • Loading branch information
Luc-Mcgrady authored Jul 23, 2023
1 parent 9fa23d1 commit ecb5c0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
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)

0 comments on commit ecb5c0e

Please sign in to comment.