xuyonghao
2024-12-30 93501af060bf8656c308ccf6319cf41cd5687c05
定时删除没有被下载的excel文件
1个文件已修改
24 ■■■■ 已修改文件
app/utils/excelmerge/conformity.py 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/utils/excelmerge/conformity.py
@@ -2,9 +2,12 @@
import random
import shutil
import string
from datetime import datetime
import threading
import time
from datetime import datetime
from openpyxl import load_workbook
from Log import logger
def clear_blank_rows(sheet):
@@ -21,6 +24,20 @@
                source_sheet.cell(row=row, column=col).value for col in range(4, source_sheet.max_column + 1)):
            target_sheet.append(
                [source_sheet.cell(row=row, column=col).value for col in range(1, source_sheet.max_column + 1)])
def delete_file_after_delay(file_path, delay_minutes):
    delay_seconds = delay_minutes * 60
    def delete_file():
        time.sleep(delay_seconds)
        try:
            if os.path.exists(file_path):
                os.remove(file_path)
        except Exception as e:
            logger.error(f"定时删除Excel文件时发生错误: {e}")
    threading.Thread(target=delete_file).start()
def run_conformity(file_path, print_path):
@@ -65,10 +82,11 @@
        template_excel.save(output_path)
        template_excel.close()
        # 合并完成后删除无用文件
        delete_file_after_delay(output_path, 5)
        try:
        for filename in os.listdir(file_path):
            file_path_full = os.path.join(file_path, filename)
            try:
                if os.path.isfile(file_path_full) or os.path.islink(file_path_full):
                    os.unlink(file_path_full)
                elif os.path.isdir(file_path_full):