amznMailConverter/webSimple.py

55 lines
2.3 KiB
Python

#!/scrapy/venvs/amznMailConverter/bin/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')]
file_list.sort(key=lambda a: a.lower())
# Get the current timestamp
generation_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# HTML content with dark and blue-themed Material Design styling
html_content = f'''<html>
<head>
<title>PDF Files</title>
<style>
body {{ font-family: Arial, sans-serif; background-color: #121212; color: #e0e0e0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }}
.container {{ max-width: 600px; background: #1e1e1e; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5); border-radius: 8px; padding: 20px; text-align: center; }}
h2 {{ color: #bb86fc; font-size: 24px; margin-bottom: 20px; }}
ul {{ list-style-type: none; padding: 0; }}
li {{ margin: 10px 0; }}
a {{ text-decoration: none; color: #03dac6; font-weight: bold; padding: 10px 15px; border-radius: 5px; transition: background-color 0.2s ease; }}
a:hover {{ background-color: #333; color: #bb86fc; }}
.footer {{ margin-top: 20px; font-size: 12px; color: #666; }}
</style>
</head>
<body>
<div class="container">
<h2>Available PDF Files for Download</h2>
<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}")