-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonHandler.py
42 lines (33 loc) · 884 Bytes
/
jsonHandler.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
import json
jsonFile = {}
#name of the json file to load in jsonFile (ext. excluded)
def loadJSON(name):
global jsonFile
try:
file = open("./docs/"+name+".json", "r")
jsonFile = json.load(file)
file.close()
return jsonFile
except:
print("Missing "+name+".json")
return False
def saveJSON(name, contents):
global jsonFile
try:
file = open("./docs/"+name+".json", "w")
json.dump(contents, file)
file.close()
return True
except:
print("Some error occured while saving "+name+".json")
return False
def addToJSON(name, contents):
global jsonFile
try:
json, ret = loadJSON(name)
if(ret == False): return False
json.update(contents)
ret = saveJSON(name, json)[1]
return ret
except:
return False