Update app.py
Browse files
app.py
CHANGED
|
@@ -274,79 +274,53 @@ def ty_le_dich_vu():
|
|
| 274 |
@app.get("/ds_pyc_cho_xu_ly")
|
| 275 |
def ds_pyc_cho_xu_ly():
|
| 276 |
try:
|
| 277 |
-
|
| 278 |
-
repo_id=REPO_ID,
|
| 279 |
-
repo_type="dataset",
|
| 280 |
-
token=HF_TOKEN
|
| 281 |
-
)
|
| 282 |
-
|
| 283 |
-
pyc_files = [
|
| 284 |
-
f for f in all_files
|
| 285 |
-
if f.startswith("Khach_hang/")
|
| 286 |
-
and "/Phieu_yeu_cau/" in f
|
| 287 |
-
and f.lower().endswith(".xlsx")
|
| 288 |
-
]
|
| 289 |
-
|
| 290 |
-
gcn_files = [
|
| 291 |
-
f for f in all_files
|
| 292 |
-
if f.startswith("Khach_hang/")
|
| 293 |
-
and "/Scan/" in f
|
| 294 |
-
and "GCN" in os.path.basename(f).upper()
|
| 295 |
-
]
|
| 296 |
-
|
| 297 |
-
khach_co_gcn = set(f.split("/")[1] for f in gcn_files if len(f.split("/")) >= 3)
|
| 298 |
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
for file in pyc_files:
|
| 302 |
-
parts = file.split("/")
|
| 303 |
-
if len(parts) < 3:
|
| 304 |
-
continue
|
| 305 |
|
| 306 |
-
|
| 307 |
-
if ten_khach in khach_co_gcn:
|
| 308 |
-
continue # đã hoàn thành
|
| 309 |
|
|
|
|
| 310 |
try:
|
| 311 |
-
|
|
|
|
| 312 |
repo_id=REPO_ID,
|
| 313 |
repo_type="dataset",
|
| 314 |
-
filename=
|
| 315 |
token=HF_TOKEN,
|
| 316 |
cache_dir="/tmp"
|
| 317 |
)
|
| 318 |
-
|
| 319 |
-
wb = load_workbook(local, data_only=True)
|
| 320 |
sheet = wb.active
|
| 321 |
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
"
|
| 327 |
-
"
|
| 328 |
-
"AY","AZ","BA","BB","BC","BD","BE","BF","BG","BH","BI","BJ","BK",
|
| 329 |
-
"BL","BM","BN","BO","BP","BQ","BR","BS","BT","BU","BV","BW","BX",
|
| 330 |
-
"BY","BZ","CA","CB","CC","CD"
|
| 331 |
]
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
"
|
|
|
|
|
|
|
|
|
|
| 343 |
})
|
| 344 |
-
|
| 345 |
except Exception as e:
|
| 346 |
-
print(f"Lỗi đọc
|
| 347 |
continue
|
| 348 |
|
| 349 |
-
return
|
| 350 |
|
| 351 |
except Exception as e:
|
| 352 |
return {"error": str(e)}
|
|
|
|
| 274 |
@app.get("/ds_pyc_cho_xu_ly")
|
| 275 |
def ds_pyc_cho_xu_ly():
|
| 276 |
try:
|
| 277 |
+
from utils.list_repo_files import list_repo_files # Đảm bảo utils có hàm này
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
danh_sach_cho_xu_ly = []
|
|
|
|
|
|
|
| 283 |
|
| 284 |
+
for f in ds_pyc:
|
| 285 |
try:
|
| 286 |
+
khach = f.split("/")[1]
|
| 287 |
+
local_file = hf_hub_download(
|
| 288 |
repo_id=REPO_ID,
|
| 289 |
repo_type="dataset",
|
| 290 |
+
filename=f,
|
| 291 |
token=HF_TOKEN,
|
| 292 |
cache_dir="/tmp"
|
| 293 |
)
|
| 294 |
+
wb = load_workbook(local_file, data_only=True)
|
|
|
|
| 295 |
sheet = wb.active
|
| 296 |
|
| 297 |
+
# Người lập phiếu
|
| 298 |
+
nguoi_lap = sheet["AH51"].value
|
| 299 |
+
nguoi_lap = nguoi_lap.strip() if isinstance(nguoi_lap, str) else ""
|
| 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 |
+
# Ngày lập phiếu
|
| 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 |
+
danh_sach_cho_xu_ly.append({
|
| 314 |
+
"Khách hàng": khach,
|
| 315 |
+
"File PYC": os.path.basename(f),
|
| 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 {f}: {e}")
|
| 321 |
continue
|
| 322 |
|
| 323 |
+
return danh_sach_cho_xu_ly
|
| 324 |
|
| 325 |
except Exception as e:
|
| 326 |
return {"error": str(e)}
|