-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_json.py
More file actions
38 lines (32 loc) · 926 Bytes
/
populate_json.py
File metadata and controls
38 lines (32 loc) · 926 Bytes
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
import os, json
static_dir = os.listdir(".\static")
fnames = []
temp = dict()
for i in static_dir:
for j in os.listdir(f".\static\{i}"):
name_file = (j.split(".")[0]).replace("_"," ")
temp["name"] = f"{name_file}"
j_n = j.replace(" ","_")
temp["name_w"] = j_n.split(".")[0]
os.rename(f".\static\{i}\{j}",f".\static\{i}\{j_n}")
temp["url"] = f".\static\{i}\{j_n}"
temp["loc"] = i
fnames.append(str(temp))
'''
NOTE for Future work
output comes like: [
str(dict),....
]
expected is [
dict,....
]
Cause of this issue: "\\" is getting converted to "\\\\"
also dict is as string (which means
"{ => {
and
"} => }
)
make sure to convert the SdRd to S'R' (only in name)
'''
with open("gate_data.json","w") as f:
json.dump(fnames,f,indent=4)