-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_menu.py
More file actions
36 lines (28 loc) · 813 Bytes
/
generate_menu.py
File metadata and controls
36 lines (28 loc) · 813 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
#!/bin/python
import os
def generate_htmls_for_links(links):
newline = '<BR/>\n'
html = f"""
<html>
<body>
{newline.join(map(lambda link: f"<a href='{link}'>{link}</a>", links))}
</body>
</html>
"""
return html
def read_links():
links = []
for dir in os.listdir(os.getcwd()):
prefixed_dir = "./" + dir
if os.path.isdir(prefixed_dir) and not dir.startswith(".") and os.listdir(prefixed_dir).count("index.html"):
links.append(prefixed_dir)
return links
def main():
links = read_links()
html = generate_htmls_for_links(links)
with open("index.html", "w") as file:
file.write(html)
print("Generated links: ")
for l in links:
print("\t", l)
main()