-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsavedata.py
62 lines (49 loc) · 1.61 KB
/
savedata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
savedata.py: Responsible for reading and writing to the save.json file and remembering certain useful things like passwords
Contributors: Andrew Combs
"""
import json
import errno
import os
# TODO: store data better
version = 1.4
authors = ["Jackson Elia", "Andrew Combs"]
functionality = "Full Auto"
visible = True
timeout = 15
wait = 0
username = ""
password = ""
class JSONManager(object):
def __init__(self, fp: str=""):
if os.path.exists(fp):
self.fp = fp + "\save.json"
else:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), fp)
return
# TODO: Have a better way of making sure that all options exist in the save file
if not os.path.exists(self.fp):
self.buffer = {
"version": version,
"authors": authors,
"functionality": functionality,
"visible": visible,
"timeout": timeout,
"wait": wait,
"username": username,
"password": password,
}
dump = json.dumps(self.buffer)
with open(self.fp, "w") as jsonfile:
jsonfile.write(dump)
return
def read(self) -> dict:
with open(self.fp, "r") as jsonfile:
data = jsonfile.read()
self.buffer = json.loads(data)
return self.buffer
def write(self, data: dict):
self.buffer = data
dump = json.dumps(self.buffer)
with open(self.fp, "w") as jsonfile:
jsonfile.write(dump)