-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreationJson.py
50 lines (44 loc) · 1.02 KB
/
creationJson.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
43
44
45
46
47
48
49
50
import json
ROLL_NUMBER = 0
NOTE = 1
HYGIEN = 2
FOUR = 3
FIVE = 4
SIX = 5
SEVEN = 6
def fill_data_field(info, d):
if info[HYGIEN]:
d["data"]["hygien"] = info[HYGIEN]
if info[FOUR]:
d["data"]["four"] = info[FOUR]
if info[FIVE]:
d["data"]["five"] = info[FIVE]
if info[SIX]:
d["data"]["six"] = info[SIX]
if info[SEVEN]:
d["data"]["seven"] = info[SEVEN]
return (d)
def remove_last_coma(f):
f.seek(0, 2)
f.seek(f.tell() - 2, 0)
f.truncate()
def createJson(infos):
f = open("data.json", "w")
f.write("[")
for info in infos:
d = {
"Roll_No": info[ROLL_NUMBER],
"note": info[NOTE],
"data":{},
}
d = fill_data_field(info, d)
json.dump(d, f, indent=4)
f.write(",\n")
remove_last_coma(f)
f.write("]")
if __name__ == '__main__':
test = [[12, 12, 0, 0, 0, 0, 0],
[5, 6, 0, 0, 0, 70, 0],
[19, 5, 0, 2, 50, 0, 0]
]
createJson(test)