-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentable.py
54 lines (40 loc) · 1.07 KB
/
gentable.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
51
52
53
54
from pathlib import Path
tmp_folders = []
folders = []
files = []
result = []
lines = 0
import os
rootdir = './Content'
outputfile = 'README.md'
print("Detected Categories")
print("-------------------")
for file in os.listdir(rootdir):
d = os.path.join(rootdir, file)
if os.path.isdir(d) and d != './.git':
tmp_folders.append(d)
d = d[2:].split('/')[-1]
print(d)
folders.append(str(f"| {d} | "))
for a in tmp_folders:
a = a[2:]
a = str(a)
folder_name = a
folder = Path(folder_name)
if folder.is_dir():
folder_count = len([1 for asa in folder.iterdir()])
files.append(str(f"{folder_count} |"))
result = map(sum, zip(str(folders),str(files)))
result = [x+y for x, y in zip(folders, files)]
readme = open(outputfile, 'r+')
file_lines = readme.readlines()
for line in file_lines:
lines += 1
readme.seek(0)
readme.truncate()
readme.writelines(file_lines[:6])
for listitem in result:
readme.write('%s\n' % listitem)
readme.write('\n</div>')
print("-------------------")
print("\nWritten to", outputfile)