New file |
| | |
| | | import os.path |
| | | from datetime import datetime, timedelta |
| | | |
| | | |
| | | def delete_file_after_delay(): |
| | | path = "data/output" |
| | | data_dir = os.path.dirname(path) |
| | | if not os.path.exists(data_dir): |
| | | return |
| | | if not os.path.exists(path): |
| | | return |
| | | now = datetime.now() |
| | | five_minutes_ago = now - timedelta(minutes=5) |
| | | for filename in os.listdir(path): |
| | | file_path = os.path.join(path, filename) |
| | | if os.path.isfile(file_path): |
| | | creation_time = os.path.getctime(file_path) |
| | | file_creation_datetime = datetime.fromtimestamp(creation_time) |
| | | if file_creation_datetime < five_minutes_ago: |
| | | os.remove(file_path) |
| | | print(f"定时删除文件: {file_path}") |
| | |
| | | |
| | | from datetime import datetime |
| | | from openpyxl import load_workbook |
| | | from Log import logger |
| | | |
| | | |
| | | def clear_blank_rows(sheet): |
| | |
| | | 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): |
| | | from main import scheduler |
| | | |
| | | def delete_file(): |
| | | try: |
| | | if os.path.exists(file_path): |
| | | os.remove(file_path) |
| | | except Exception as e: |
| | | logger.error(f"定时删除Excel文件时发生错误: {e}") |
| | | |
| | | scheduler.add_job(delete_file, 'interval', minutes=delay_minutes, id=f"delete_{file_path}") |
| | | |
| | | |
| | | def run_conformity(file_path, print_path): |
| | |
| | | output_path = os.path.join(print_path, f'{file_name}.xlsx') |
| | | template_excel.save(output_path) |
| | | template_excel.close() |
| | | |
| | | delete_file_after_delay(output_path, 3) |
| | | |
| | | try: |
| | | for filename in os.listdir(file_path): |
| | |
| | | from app.api.group import group_router |
| | | from app.api.role import role_router |
| | | from app.models.base_model import init_db |
| | | from app.task.delete_execl_file import delete_file_after_delay |
| | | # from app.models.base_model import init_db |
| | | from app.task.fetch_agent import sync_agents, initialize_agents, sync_agents_v2, sync_knowledge, \ |
| | | sync_resources_from_json |
| | |
| | | # 创建调度器 |
| | | scheduler = BackgroundScheduler() |
| | | scheduler.add_job(sync_agents_v2, 'interval', minutes=60, id="sync_resource_data") |
| | | scheduler.add_job(delete_file_after_delay, 'interval', minutes=10, id="delete_file_after_delay") |
| | | scheduler.start() |
| | | |
| | | app.include_router(auth_router, prefix='/api/auth', tags=["auth"]) |