summaryrefslogtreecommitdiffstats
path: root/flashcards-project/src/flashcards/state_json.py
blob: 673d904702917bc6025b50b0e5e904a26a956680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Helper functions to store scheduler state as json
"""
import json
from pathlib import Path

def save(file: str, state: dict) -> None:
    """
    Dump the specified state dictionary in JSON format
    """
    with open(file, "w") as f:
        json.dump(state, f)

def load(file: str) -> dict:
    """
    Load the state from the specified file and return
    an empty dictionary silently if the file doesn't exist.
    """
    try:
        with open(file, "r") as f:
            return json.load(f)
    except:
        return {}