1
0
Fork 0
mirror of synced 2024-06-02 18:54:33 +12:00

Truncated file to fix issue when new content is less than old content

This commit is contained in:
Phxntxm 2016-07-17 12:11:47 -05:00
parent e51251d435
commit a2fe435323

View file

@ -44,16 +44,20 @@ def closeConnection():
def saveContent(key: str, content):
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
data = json.load(jf)
data[key] = content
jf.seek(0)
json.dump(data, jf, indent=4)
jf.close()
newData = dict(data)
newData[key] = content
jf.truncate()
try:
json.dump(newData, jf, indent=4)
except:
json.dump(data, jf, indent=4)
def getContent(key: str):
try:
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
data = json.load(jf)
jf.close()
return data[key]
except KeyError:
return None