|
@@ -1,20 +1,24 @@
|
|
|
|
+from datetime import datetime
|
|
|
|
+
|
|
|
|
+
|
|
def save_html_to_file(html_content, file_name):
|
|
def save_html_to_file(html_content, file_name):
|
|
import os
|
|
import os
|
|
# 保存 HTML 文件的路径,假设保存到 /home 目录下
|
|
# 保存 HTML 文件的路径,假设保存到 /home 目录下
|
|
- file_path = f"/home/aihtml"
|
|
|
|
|
|
+
|
|
|
|
+ current_time = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
|
|
+ file_path = f"/home/aihtml/{file_name}_{current_time}.html"
|
|
directory = os.path.dirname(file_path)
|
|
directory = os.path.dirname(file_path)
|
|
if not os.path.exists(directory):
|
|
if not os.path.exists(directory):
|
|
os.makedirs(directory)
|
|
os.makedirs(directory)
|
|
- rs_name = f"{file_path}/{file_name}.html"
|
|
|
|
try:
|
|
try:
|
|
# 打开文件并写入 HTML 内容
|
|
# 打开文件并写入 HTML 内容
|
|
- with open(rs_name, "w", encoding="utf-8") as file:
|
|
|
|
|
|
+ with open(file_path, "w", encoding="utf-8") as file:
|
|
file.write(html_content)
|
|
file.write(html_content)
|
|
- print(f"HTML 文件已成功保存到 {rs_name}")
|
|
|
|
|
|
+ print(f"HTML 文件已成功保存到 {file_path}")
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(f"保存文件时出现错误: {e}")
|
|
print(f"保存文件时出现错误: {e}")
|
|
|
|
|
|
- return f"{file_name}.html"
|
|
|
|
|
|
+ return f"{file_name}_{current_time}.html"
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|