-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
46 lines (30 loc) · 894 Bytes
/
config.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
from pathlib import Path
import json
PATH_CONFIG = Path(Path(__file__).parent.absolute(), "config.json")
DEFAULT_CONFIG = {
"Target": "CPU",
"FPS": 5,
"Click rate": "Normal",
"Key": "F"
}
def default_config():
write_config(DEFAULT_CONFIG)
def read_config():
with open(PATH_CONFIG) as file:
return json.loads(file.read())
def write_config(config):
with open(PATH_CONFIG, "w") as file:
file.write(json.dumps(config, indent=4))
def update_config(key, value):
config = read_config()
config[key] = value
write_config(config)
if not PATH_CONFIG.exists():
default_config()
print("Create config")
if __name__ == '__main__':
print("Default config:", read_config())
update_config("Target", "CUDA")
update_config("FPS", 0)
update_config("Click rate", "Fast")
print("Config after update: ", read_config())