amznMailConverter/webSimple.py

61 lines
2.7 KiB
Python

import os
from datetime import datetime
def generate_pdf_list_html(directory, output_file="pdf_list.html"):
"""Generate an HTML file listing PDF files in the specified directory with the generation timestamp."""
try:
# Get a list of PDF files in the directory
file_list = [f for f in os.listdir(directory) if f.endswith('.pdf')]
# Sort files by modification time (newest first)
file_list.sort(key=lambda f: os.path.getmtime(os.path.join(directory, f)), reverse=True)
# Get the current timestamp
generation_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# HTML content with updated styling and auto-refresh
html_content = f'''<html>
<head>
<title>PDF Files</title>
<meta http-equiv="refresh" content="60"> <!-- Auto-refresh every 60 seconds -->
<style>
body {{ font-family: "Courier New", Courier, monospace; background-color: #0d1b2a; color: #e0e0e0; margin: 0; padding: 100px; }}
.container {{ max-width: 800px; background: #1b2631; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5); border-radius: 12px; padding: 30px; margin: auto; margin-top: 40px; }}
h2 {{ color: #00bfff; font-size: 28px; margin-bottom: 10px; }}
.separator {{ border-top: 2px solid #00bfff; margin-bottom: 50px; }}
ul {{ list-style-type: none; padding: 0; }}
li {{ margin: 15px 0; }}
a {{ text-decoration: none; color: #00bfff; font-weight: bold; padding: 10px 15px; border-radius: 5px; transition: background-color 0.2s ease; }}
a:hover {{ background-color: #005f7f; color: #ffffff; }}
.footer {{ margin-top: 60px; font-size: 12px; color: #bbb; }}
</style>
</head>
<body>
<div class="container">
<h2>Available PDF Files for Download</h2>
<div class="separator"></div>
<ul>'''
for name in file_list:
html_content += f'<li><a href="data/{name}" download>{name}</a></li>'
html_content += f'''</ul>
<div class="footer">Generated on: {generation_time}</div>
</div>
</body>
</html>'''
# Write the HTML content to the output file
with open(output_file, "w") as file:
file.write(html_content)
print(f"HTML file generated at: {os.path.abspath(output_file)}")
except Exception as e:
print(f"An error occurred: {e}")
# Usage
if __name__ == "__main__":
directory = 'amznMailConverter/data'
output_file = os.path.join(directory, "pdf_list.html")
generate_pdf_list_html(directory, output_file)