Corrected how to create the config.json file if it does not exist
This commit is contained in:
parent
c95bdcbd96
commit
d14df8e3ea
1 changed files with 10 additions and 6 deletions
|
@ -33,12 +33,16 @@ except KeyError:
|
|||
|
||||
|
||||
def saveContent(key: str, content):
|
||||
with open("config.json", "a+") as jf:
|
||||
data = json.load(jf)
|
||||
data[key] = content
|
||||
jf.seek(0)
|
||||
jf.truncate()
|
||||
json.dump(data, jf, indent=4)
|
||||
try:
|
||||
with open("config.json", "r+") as jf:
|
||||
data = json.load(jf)
|
||||
data[key] = content
|
||||
jf.seek(0)
|
||||
jf.truncate()
|
||||
json.dump(data, jf, indent=4)
|
||||
except FileNotFoundError:
|
||||
with open("config.json", "w+") as jf:
|
||||
json.dump({key: content}, jf, indent=4)
|
||||
|
||||
|
||||
def getContent(key: str):
|
||||
|
|
Loading…
Reference in a new issue