summaryrefslogtreecommitdiffstats
path: root/src/flashcard_cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/flashcard_cli.py')
-rw-r--r--src/flashcard_cli.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/flashcard_cli.py b/src/flashcard_cli.py
index 95da182..7f5da34 100644
--- a/src/flashcard_cli.py
+++ b/src/flashcard_cli.py
@@ -1,10 +1,10 @@
import click
-from json import load, dump
from random import shuffle
from card import Card
from scheduler import getSchedulerClass, SCHEDULERS
from parser import parseFiles
+from state_json import save, load
@click.group()
def cli():
@@ -21,12 +21,7 @@ def practice(state_file, card_files, scheduler_name, count, random_flip):
Run a practice session with the specified scheduler, using the provided state and card files.
"""
all_cards = parseFiles(card_files)
-
- try:
- state = json.load(state_file)
- except:
- click.echo(f"Warning: could not load state from {state_file}, starting with clean state")
- state = {}
+ state = load(state_file)
scheduler = getSchedulerClass(scheduler_name)(all_cards, state)
@@ -55,13 +50,7 @@ def test(state_file, card_files, scheduler_name, count, random_flip):
Run a test session with the specified scheduler, using the provided state and card files.
"""
all_cards = parseFiles(card_files)
-
- try:
- with open(state_file, "r") as f:
- state = load(f)
- except:
- click.echo(f"Warning: could not load state from {state_file}, starting with clean state")
- state = {}
+ state = load(state_file)
scheduler = getSchedulerClass(scheduler_name)(all_cards, state)
@@ -84,9 +73,7 @@ def test(state_file, card_files, scheduler_name, count, random_flip):
results[id] = int(click.confirm(click.style("Correct?", bold=True)))
scheduler.update(results)
-
- with open(state_file, "w") as f:
- dump(scheduler.getState(), f)
+ save(state_file, scheduler.getState())
if __name__ == '__main__':
cli()