-
Notifications
You must be signed in to change notification settings - Fork 2
/
sheets.py
executable file
·39 lines (33 loc) · 991 Bytes
/
sheets.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
#!/usr/bin/python
import os
import io
import json
from pathlib import Path
# Hmmm I should have just used node for this huh, then I wouldn't have to deal with python versions
# but python tho....
dirFile = 'src/data/sheets.json'
dirname = Path(__file__).parent
def scan(currentDir = os.path.join(dirname, 'public', 'sheets')):
obj = {}
scanDir = os.scandir(currentDir)
currentDir = currentDir.replace('\\', '/')
name = currentDir.split('/')[-1]
currentDir += '/'
obj['name'] = name
obj['full_path'] = currentDir.split('/public')[1]
contents = []
for i in scanDir:
if i.name == dirFile or i.name == __file__:
continue
if not i.is_dir():
contents.append(i.name)
else:
contents.append(scan(i.path))
obj['contents'] = contents
return obj
def write(dirs = {}, name = dirFile):
with io.open(name, "w", encoding="utf-8") as f:
json_str = json.dumps(dirs,indent=2)
f.write(json_str)
write(scan())
print('sheets.json generated! :)')