1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00
AdvLabDB/advlabdb/configUtils.py

27 lines
575 B
Python
Raw Normal View History

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:
2022-01-13 01:25:31 +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