Update app.py
Browse files
app.py
CHANGED
|
@@ -271,56 +271,64 @@ def ty_le_dich_vu():
|
|
| 271 |
|
| 272 |
except Exception as e:
|
| 273 |
return {"error": str(e)}
|
|
|
|
| 274 |
@app.get("/ds_pyc_cho_xu_ly")
|
| 275 |
-
def ds_pyc_cho_xu_ly():
|
| 276 |
try:
|
| 277 |
-
|
| 278 |
-
|
| 279 |
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
| 280 |
-
ds_pyc = [f for f in all_files if f.startswith("Khach_hang/") and "/Phieu_yeu_cau/" in f and f.endswith(".xlsx")]
|
| 281 |
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
-
for
|
| 285 |
try:
|
| 286 |
-
|
| 287 |
-
local_file = hf_hub_download(
|
| 288 |
repo_id=REPO_ID,
|
| 289 |
repo_type="dataset",
|
| 290 |
-
filename=
|
| 291 |
token=HF_TOKEN,
|
| 292 |
cache_dir="/tmp"
|
| 293 |
)
|
| 294 |
-
|
|
|
|
| 295 |
sheet = wb.active
|
| 296 |
|
| 297 |
-
#
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
ten_duoc_chap_nhan = [
|
| 301 |
-
"Nguyễn Duy Thảo", "Lê Danh Huy", "Nguyễn Mạnh Cường",
|
| 302 |
-
"Trần Văn Dương", "Nguyễn Ngọc Vinh"
|
| 303 |
-
]
|
| 304 |
-
if nguoi_lap not in ten_duoc_chap_nhan:
|
| 305 |
-
nguoi_lap = "Không xác định"
|
| 306 |
|
| 307 |
-
|
| 308 |
ngay = sheet["BM3"].value
|
| 309 |
thang = sheet["BS3"].value
|
| 310 |
nam = sheet["BX3"].value
|
| 311 |
-
ngay_lap = f"{ngay}/{thang}/{nam}" if all([ngay, thang, nam]) else "Không rõ"
|
| 312 |
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
"Người lập": nguoi_lap,
|
| 317 |
"Ngày lập": ngay_lap
|
| 318 |
})
|
|
|
|
| 319 |
except Exception as e:
|
| 320 |
-
print(f"Lỗi đọc file {
|
| 321 |
continue
|
| 322 |
|
| 323 |
-
return
|
| 324 |
|
| 325 |
except Exception as e:
|
| 326 |
-
return {"error": str(e)}
|
|
|
|
|
|
| 271 |
|
| 272 |
except Exception as e:
|
| 273 |
return {"error": str(e)}
|
| 274 |
+
|
| 275 |
@app.get("/ds_pyc_cho_xu_ly")
|
| 276 |
+
async def ds_pyc_cho_xu_ly():
|
| 277 |
try:
|
| 278 |
+
# Tìm tất cả file PYC trong repo
|
| 279 |
+
from huggingface_hub import list_repo_files
|
| 280 |
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
|
|
|
| 281 |
|
| 282 |
+
pyc_files = [
|
| 283 |
+
f for f in all_files
|
| 284 |
+
if f.startswith("Khach_hang/") and "/Phieu_yeu_cau/" in f and f.endswith(".xlsx")
|
| 285 |
+
]
|
| 286 |
+
|
| 287 |
+
ket_qua = []
|
| 288 |
+
ten_nguoi_lap_hop_le = [
|
| 289 |
+
"Nguyễn Duy Thảo", "Lê Danh Huy", "Nguyễn Mạnh Cường", "Trần Văn Dương", "Nguyễn Ngọc Vinh"
|
| 290 |
+
]
|
| 291 |
|
| 292 |
+
for file in pyc_files:
|
| 293 |
try:
|
| 294 |
+
local_path = hf_hub_download(
|
|
|
|
| 295 |
repo_id=REPO_ID,
|
| 296 |
repo_type="dataset",
|
| 297 |
+
filename=file,
|
| 298 |
token=HF_TOKEN,
|
| 299 |
cache_dir="/tmp"
|
| 300 |
)
|
| 301 |
+
|
| 302 |
+
wb = load_workbook(local_path, data_only=True)
|
| 303 |
sheet = wb.active
|
| 304 |
|
| 305 |
+
# Lấy dữ liệu
|
| 306 |
+
ten_khach = file.split("/")[1]
|
| 307 |
+
ten_file = file.split("/")[-1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
+
nguoi_lap = sheet["AH51"].value
|
| 310 |
ngay = sheet["BM3"].value
|
| 311 |
thang = sheet["BS3"].value
|
| 312 |
nam = sheet["BX3"].value
|
|
|
|
| 313 |
|
| 314 |
+
if nguoi_lap not in ten_nguoi_lap_hop_le:
|
| 315 |
+
continue
|
| 316 |
+
|
| 317 |
+
ngay_lap = f"{ngay:02}/{thang:02}/{nam}" if all([ngay, thang, nam]) else "Không rõ"
|
| 318 |
+
|
| 319 |
+
ket_qua.append({
|
| 320 |
+
"Khách hàng": ten_khach,
|
| 321 |
+
"File PYC": ten_file,
|
| 322 |
"Người lập": nguoi_lap,
|
| 323 |
"Ngày lập": ngay_lap
|
| 324 |
})
|
| 325 |
+
|
| 326 |
except Exception as e:
|
| 327 |
+
print(f"Lỗi đọc file {file}: {e}")
|
| 328 |
continue
|
| 329 |
|
| 330 |
+
return JSONResponse(content=ket_qua)
|
| 331 |
|
| 332 |
except Exception as e:
|
| 333 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 334 |
+
|