Create danh_muc_thiet_bi.py
Browse files- routes/danh_muc_thiet_bi.py +30 -0
routes/danh_muc_thiet_bi.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import openpyxl
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
router = APIRouter()
|
| 8 |
+
|
| 9 |
+
@router.get("/danh_muc_thiet_bi")
|
| 10 |
+
async def danh_muc_thiet_bi():
|
| 11 |
+
try:
|
| 12 |
+
path = hf_hub_download(
|
| 13 |
+
repo_id="doluong6/Quatest1",
|
| 14 |
+
filename="Quan ly thiet bi, dung cu - 25.03.28.xlsx",
|
| 15 |
+
repo_type="dataset",
|
| 16 |
+
token=os.environ.get("HF_TOKEN"),
|
| 17 |
+
cache_dir="/tmp"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
wb = openpyxl.load_workbook(path, data_only=True)
|
| 21 |
+
ws = wb["DUNG CU SU DUNG"]
|
| 22 |
+
|
| 23 |
+
data = []
|
| 24 |
+
for row in ws.iter_rows(values_only=True):
|
| 25 |
+
if any(row):
|
| 26 |
+
data.append([str(cell) if cell is not None else "" for cell in row])
|
| 27 |
+
|
| 28 |
+
return JSONResponse(content={"data": data})
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|