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''' PDF Files

Available PDF Files for Viewing

''' # 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)