summaryrefslogtreecommitdiff
path: root/jstate/jstate.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-04-20 00:19:27 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-04-20 00:21:17 +0300
commit2822361b3bccc854548da3213fe8afb622d11a8a (patch)
treee9940162a69d0f77f0f6e36e9e69bdb646ce63a4 /jstate/jstate.py
initialHEADmaster
Diffstat (limited to 'jstate/jstate.py')
-rw-r--r--jstate/jstate.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/jstate/jstate.py b/jstate/jstate.py
new file mode 100644
index 0000000..799f924
--- /dev/null
+++ b/jstate/jstate.py
@@ -0,0 +1,21 @@
+import os, json
+
+
+class JState:
+ def __init__(self, file: str, default=None):
+ if default is None:
+ default = {}
+ self.file = file
+ self.default = default
+
+ def read(self) -> dict:
+ if not os.path.exists(self.file):
+ self.write(self.default)
+ return self.default
+
+ with open(self.file, 'r') as f:
+ return json.loads(f.read())
+
+ def write(self, state: dict):
+ with open(self.file, 'w') as f:
+ f.write(json.dumps(state)) \ No newline at end of file