Ask ChatGPT to port to python

main
Stef Dunlap 2023-02-21 12:57:12 -05:00
parent f18f9164ba
commit 48f03ecb59
1 changed files with 26 additions and 0 deletions

26
fishyindex.py 100755
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import os
from datetime import datetime
def mkindex(DIR):
FILE = os.path.join(DIR, 'index.html')
with open(FILE, 'w') as f:
f.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>')
f.write('<table><thead><tr><th>Name</th><th>Last Modified</th></tr></thead><tbody>')
for f in os.listdir(DIR):
if os.path.isdir(os.path.join(DIR, f)):
f += '/'
timestamp = datetime.fromtimestamp(os.path.getmtime(os.path.join(DIR, f))).strftime('%Y-%m-%d %H:%M:%S')
f = f'<tr><td><a href="{f}">{f}</a></td><td><span style="color: #888;">{timestamp}</span></td></tr>'
f.write(f)
f.write('</tbody></table></body></html>')
def index_for_all(DIR):
mkindex(DIR)
for d in os.listdir(DIR):
if os.path.isdir(os.path.join(DIR, d)):
index_for_all(os.path.join(DIR, d))
index_for_all(os.getcwd())