2021-06-01 23:56:49 +00:00
|
|
|
import json
|
|
|
|
|
2021-06-02 21:43:41 +00:00
|
|
|
|
2021-06-01 23:56:49 +00:00
|
|
|
def getConfig(label):
|
|
|
|
with open("config.json", "r") as f:
|
2021-06-02 21:43:41 +00:00
|
|
|
return json.load(f)[label] # TODO error handling
|
2021-06-01 23:56:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setConfig(label, value, new=False):
|
|
|
|
with open("config.json", "r") as f:
|
|
|
|
config = json.load(f)
|
|
|
|
|
|
|
|
if new and (label in config):
|
|
|
|
# Setting is not new! # TODO
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not new and (label not in config):
|
|
|
|
# Tried to update a setting which is new! # TODO
|
|
|
|
return False
|
|
|
|
|
|
|
|
config[label] = value
|
|
|
|
|
|
|
|
with open("config.json", "w") as f:
|
|
|
|
json.dump(config, f)
|
|
|
|
|
|
|
|
return True
|