From 962116115afd0781d8b7f2a7315c427581f18201 Mon Sep 17 00:00:00 2001
From: xuyonghao <898441624@qq.com>
Date: 星期三, 18 十二月 2024 10:37:32 +0800
Subject: [PATCH] 修改excel脚本
---
app/api/excel.py | 24 +++++++++---------------
1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/app/api/excel.py b/app/api/excel.py
index 77ae5fd..a21ee3f 100644
--- a/app/api/excel.py
+++ b/app/api/excel.py
@@ -1,13 +1,7 @@
-from fastapi import APIRouter, File, UploadFile, Depends
+from fastapi import APIRouter, File, UploadFile
from fastapi.responses import JSONResponse, FileResponse
from fastapi.exceptions import HTTPException
-from sqlalchemy.orm import Session
-from starlette.websockets import WebSocket, WebSocketDisconnect
-from werkzeug.utils import secure_filename
-from app.api import get_current_user_websocket
-from app.models.agent_model import AgentModel, AgentType
-from app.models.base_model import get_db
-from app.models.user_model import UserModel
+from starlette.websockets import WebSocket
from app.utils.excelmerge.conformity import run_conformity
import shutil
import os
@@ -17,6 +11,7 @@
ALLOWED_EXTENSIONS = {'xlsx'}
EXCEL_FILES_PATH = 'data/output'
SOURCE_FILES_PATH = 'data/source'
+
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@@ -77,19 +72,18 @@
data = await websocket.receive_text()
try:
if data == "\"鍚堝苟Excel\"":
- output_file_path = run_conformity()
- output_file_path = run_conformity()
+ run_excel = run_conformity()
files = os.listdir(EXCEL_FILES_PATH)
- if files:
+ if run_excel:
first_file = files[0]
file_name = os.path.basename(first_file)
- file_url = f"./api/document/download/{first_file}"
+ download_url = f"./api/document/download/{first_file}"
await websocket.send_json({
"message": "鏂囨。鍚堝苟鎴愬姛锛�",
"type": "stream",
"files": [{
"file_name": file_name,
- "file_url": file_url
+ "file_url": download_url
}]
})
await websocket.send_json({
@@ -97,7 +91,7 @@
"type": "close",
})
else:
- await websocket.send_json({"error": "鍚堝苟鎿嶄綔鏈敓鎴愭枃浠�", "type": "stream", "files": []})
+ await websocket.send_json({"error": "鍚堝苟澶辫触", "type": "stream", "files": []})
elif data == "\"鏌ヨ鍚堝苟杩涘害\"":
files = os.listdir(EXCEL_FILES_PATH)
if not files:
@@ -136,4 +130,4 @@
except FileNotFoundError:
raise HTTPException(status_code=404, detail="鏂囦欢涓嶅瓨鍦�")
except Exception as e:
- raise HTTPException(status_code=500, detail="鏈嶅姟鍣ㄩ敊璇�")
\ No newline at end of file
+ raise HTTPException(status_code=500, detail="鏈嶅姟鍣ㄩ敊璇�")
--
Gitblit v1.8.0