Update routes/ds_pyc_tat_ca.py
Browse files- routes/ds_pyc_tat_ca.py +19 -4
routes/ds_pyc_tat_ca.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import APIRouter
|
| 3 |
from huggingface_hub import list_repo_files, hf_hub_download
|
| 4 |
from openpyxl import load_workbook
|
|
@@ -14,6 +13,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 14 |
def ds_pyc_tat_ca():
|
| 15 |
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
| 16 |
|
|
|
|
| 17 |
pyc_files = [
|
| 18 |
f for f in all_files
|
| 19 |
if f.startswith("Khach_hang/")
|
|
@@ -21,9 +21,26 @@ def ds_pyc_tat_ca():
|
|
| 21 |
and f.endswith(".xlsx")
|
| 22 |
]
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
ds = []
|
| 25 |
for file in pyc_files:
|
| 26 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
local = hf_hub_download(
|
| 28 |
repo_id=REPO_ID,
|
| 29 |
repo_type="dataset",
|
|
@@ -54,7 +71,6 @@ def ds_pyc_tat_ca():
|
|
| 54 |
ngay = str(sheet["BM3"].value or "") + str(sheet["BN3"].value or "")
|
| 55 |
thang = str(sheet["BS3"].value or "") + str(sheet["BT3"].value or "")
|
| 56 |
nam = str(sheet["BX3"].value or "") + str(sheet["CA3"].value or "")
|
| 57 |
-
|
| 58 |
ngay_gui = f"Hà Nội, ngày {ngay} tháng {thang} năm {nam}".replace(" ", " ").strip()
|
| 59 |
|
| 60 |
ds.append({
|
|
@@ -67,8 +83,7 @@ def ds_pyc_tat_ca():
|
|
| 67 |
print(f"Lỗi đọc {file}: {e}")
|
| 68 |
|
| 69 |
def extract_number(ma):
|
| 70 |
-
numbers = re.findall(r"\
|
| 71 |
return int(numbers[-1]) if numbers else 0
|
| 72 |
|
| 73 |
return sorted(ds, key=lambda x: extract_number(x["ma"]))
|
| 74 |
-
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
from huggingface_hub import list_repo_files, hf_hub_download
|
| 3 |
from openpyxl import load_workbook
|
|
|
|
| 13 |
def ds_pyc_tat_ca():
|
| 14 |
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
| 15 |
|
| 16 |
+
# Lọc PYC
|
| 17 |
pyc_files = [
|
| 18 |
f for f in all_files
|
| 19 |
if f.startswith("Khach_hang/")
|
|
|
|
| 21 |
and f.endswith(".xlsx")
|
| 22 |
]
|
| 23 |
|
| 24 |
+
# Gom các file Scan chứa GCN
|
| 25 |
+
gcn_files = [
|
| 26 |
+
f for f in all_files
|
| 27 |
+
if f.startswith("Khach_hang/")
|
| 28 |
+
and "/Scan/" in f
|
| 29 |
+
and "GCN" in os.path.basename(f).upper()
|
| 30 |
+
]
|
| 31 |
+
# Lấy tên thư mục khách có GCN
|
| 32 |
+
khach_co_gcn = set(f.split("/")[1] for f in gcn_files if len(f.split("/")) >= 3)
|
| 33 |
+
|
| 34 |
ds = []
|
| 35 |
for file in pyc_files:
|
| 36 |
try:
|
| 37 |
+
parts = file.split("/")
|
| 38 |
+
if len(parts) < 3:
|
| 39 |
+
continue
|
| 40 |
+
ten_khach = parts[1]
|
| 41 |
+
if ten_khach in khach_co_gcn:
|
| 42 |
+
continue # Bỏ qua khách đã có GCN
|
| 43 |
+
|
| 44 |
local = hf_hub_download(
|
| 45 |
repo_id=REPO_ID,
|
| 46 |
repo_type="dataset",
|
|
|
|
| 71 |
ngay = str(sheet["BM3"].value or "") + str(sheet["BN3"].value or "")
|
| 72 |
thang = str(sheet["BS3"].value or "") + str(sheet["BT3"].value or "")
|
| 73 |
nam = str(sheet["BX3"].value or "") + str(sheet["CA3"].value or "")
|
|
|
|
| 74 |
ngay_gui = f"Hà Nội, ngày {ngay} tháng {thang} năm {nam}".replace(" ", " ").strip()
|
| 75 |
|
| 76 |
ds.append({
|
|
|
|
| 83 |
print(f"Lỗi đọc {file}: {e}")
|
| 84 |
|
| 85 |
def extract_number(ma):
|
| 86 |
+
numbers = re.findall(r"\d+", ma)
|
| 87 |
return int(numbers[-1]) if numbers else 0
|
| 88 |
|
| 89 |
return sorted(ds, key=lambda x: extract_number(x["ma"]))
|
|
|