-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.py
58 lines (38 loc) · 1.47 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
from json import dumps, dump, load
FILE = "/home/pi/onionbot/config.json"
class Settings(object):
"""Interface with the `config.json` settings dictionary"""
def get_setting(self, key):
with open(FILE) as json_data_file:
config = load(json_data_file)
settings = config["settings"]
try:
return settings[key]
except KeyError:
raise KeyError("Settings key not found")
def set_setting(self, key, value):
with open(FILE) as json_data_file:
config = load(json_data_file)
settings = config["settings"]
if key in settings:
settings[key] = value
config["settings"] = settings
# dump new version of config
with open(FILE, "w") as outfile:
dump(config, outfile, indent=4)
else:
raise KeyError("Settings key not found")
class Labels(object):
"""Interface with the `config.json` labels dictionary"""
def get_labels(self):
with open(FILE) as json_data_file:
config = load(json_data_file)
labels = config["labels"]
return dumps(labels)
class Classifiers(object):
"""Interface with the `config.json` classifiers dictionary"""
def get_classifiers(self):
with open(FILE) as json_data_file:
config = load(json_data_file)
classifiers = config["classifiers"]
return classifiers