Add formatting to table
parent
48f03ecb59
commit
3f58f9bcf0
|
@ -5,17 +5,18 @@ from datetime import datetime
|
||||||
|
|
||||||
def mkindex(DIR):
|
def mkindex(DIR):
|
||||||
FILE = os.path.join(DIR, 'index.html')
|
FILE = os.path.join(DIR, 'index.html')
|
||||||
with open(FILE, 'w') as f:
|
with open(FILE, 'w') as index:
|
||||||
f.write(f'<html><head><title>Index of {DIR}</title></head><body style="font-family: monospace;"><h1>Index of {DIR}</h1><hr>')
|
index.write(f'<html><head><title>Index of {DIR}</title></head><body style="font-family: monospace;"><h1>Index of {DIR}</h1><hr>')
|
||||||
f.write(f'<p>Generated on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</p>')
|
index.write(f'<p>Generated on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</p>')
|
||||||
f.write('<table><thead><tr><th>Name</th><th>Last Modified</th></tr></thead><tbody>')
|
index.write('<table width=500><thead align="left"><tr><th>Name</th><th>Last Modified</th></tr></thead><tbody>')
|
||||||
for f in os.listdir(DIR):
|
entries = os.listdir(DIR)
|
||||||
if os.path.isdir(os.path.join(DIR, f)):
|
entries = sorted([entry for entry in entries if not entry.startswith('.')])
|
||||||
f += '/'
|
for file in entries:
|
||||||
timestamp = datetime.fromtimestamp(os.path.getmtime(os.path.join(DIR, f))).strftime('%Y-%m-%d %H:%M:%S')
|
if os.path.isdir(os.path.join(DIR, file)):
|
||||||
f = f'<tr><td><a href="{f}">{f}</a></td><td><span style="color: #888;">{timestamp}</span></td></tr>'
|
file += '/'
|
||||||
f.write(f)
|
timestamp = datetime.fromtimestamp(os.path.getmtime(os.path.join(DIR, file))).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
f.write('</tbody></table></body></html>')
|
index.write(f'<tr><td><a href="{file}">{file}</a></td><td><span style="color: #888;">{timestamp}</span></td></tr>')
|
||||||
|
index.write('</tbody></table></body></html>')
|
||||||
|
|
||||||
def index_for_all(DIR):
|
def index_for_all(DIR):
|
||||||
mkindex(DIR)
|
mkindex(DIR)
|
||||||
|
|
Loading…
Reference in New Issue