From 3f58f9bcf030a8122786fdb571809a2a03c63146 Mon Sep 17 00:00:00 2001 From: Stef Dunlap Date: Wed, 22 Feb 2023 10:11:16 -0500 Subject: [PATCH] Add formatting to table --- fishyindex.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fishyindex.py b/fishyindex.py index 168dc9d..4635761 100755 --- a/fishyindex.py +++ b/fishyindex.py @@ -5,17 +5,18 @@ from datetime import datetime def mkindex(DIR): FILE = os.path.join(DIR, 'index.html') - with open(FILE, 'w') as f: - f.write(f'Index of {DIR}

Index of {DIR}


') - f.write(f'

Generated on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}

') - f.write('') - 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'' - f.write(f) - f.write('
NameLast Modified
{f}{timestamp}
') + with open(FILE, 'w') as index: + index.write(f'Index of {DIR}

Index of {DIR}


') + index.write(f'

Generated on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}

') + index.write('') + entries = os.listdir(DIR) + entries = sorted([entry for entry in entries if not entry.startswith('.')]) + for file in entries: + if os.path.isdir(os.path.join(DIR, file)): + file += '/' + timestamp = datetime.fromtimestamp(os.path.getmtime(os.path.join(DIR, file))).strftime('%Y-%m-%d %H:%M:%S') + index.write(f'') + index.write('
NameLast Modified
{file}{timestamp}
') def index_for_all(DIR): mkindex(DIR)