Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from collections import defaultdict
|
|
| 7 |
from openpyxl import load_workbook
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
import tempfile
|
|
|
|
| 10 |
import os
|
| 11 |
|
| 12 |
app = FastAPI()
|
|
@@ -199,3 +200,98 @@ def doanh_thu_dich_vu():
|
|
| 199 |
return tong
|
| 200 |
except Exception as e:
|
| 201 |
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from openpyxl import load_workbook
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
import tempfile
|
| 10 |
+
from datetime import datetime
|
| 11 |
import os
|
| 12 |
|
| 13 |
app = FastAPI()
|
|
|
|
| 200 |
return tong
|
| 201 |
except Exception as e:
|
| 202 |
return {"error": str(e)}
|
| 203 |
+
|
| 204 |
+
@app.get("/ds_pyc_tat_ca")
|
| 205 |
+
def ds_pyc_tat_ca():
|
| 206 |
+
try:
|
| 207 |
+
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
| 208 |
+
|
| 209 |
+
pyc_files = [
|
| 210 |
+
f for f in all_files
|
| 211 |
+
if f.startswith("Khach_hang/")
|
| 212 |
+
and "/Phieu_yeu_cau/" in f
|
| 213 |
+
and f.endswith(".xlsx")
|
| 214 |
+
]
|
| 215 |
+
|
| 216 |
+
ds = []
|
| 217 |
+
for file in pyc_files:
|
| 218 |
+
try:
|
| 219 |
+
local = hf_hub_download(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN, filename=file, cache_dir="/tmp")
|
| 220 |
+
wb = load_workbook(local, data_only=True)
|
| 221 |
+
sheet = wb.active
|
| 222 |
+
|
| 223 |
+
ma = sheet["BS3"].value
|
| 224 |
+
kh = sheet["I10"].value
|
| 225 |
+
ngay = sheet["I6"].value
|
| 226 |
+
ngay_gui = ngay.strftime("%Y-%m-%d") if isinstance(ngay, datetime) else str(ngay)
|
| 227 |
+
|
| 228 |
+
ds.append({
|
| 229 |
+
"ma": ma or "Kh么ng r玫",
|
| 230 |
+
"khach_hang": kh or "Kh么ng r玫",
|
| 231 |
+
"ngay_gui": ngay_gui
|
| 232 |
+
})
|
| 233 |
+
except:
|
| 234 |
+
continue
|
| 235 |
+
|
| 236 |
+
return ds
|
| 237 |
+
except Exception as e:
|
| 238 |
+
return {"error": str(e)}
|
| 239 |
+
@app.get("/ds_pyc_hoan_thanh")
|
| 240 |
+
def ds_pyc_hoan_thanh():
|
| 241 |
+
try:
|
| 242 |
+
all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
|
| 243 |
+
|
| 244 |
+
pyc_files = [
|
| 245 |
+
f for f in all_files
|
| 246 |
+
if f.startswith("Khach_hang/")
|
| 247 |
+
and "/Phieu_yeu_cau/" in f
|
| 248 |
+
and f.endswith(".xlsx")
|
| 249 |
+
]
|
| 250 |
+
|
| 251 |
+
ds = []
|
| 252 |
+
for file in pyc_files:
|
| 253 |
+
try:
|
| 254 |
+
local = hf_hub_download(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN, filename=file, cache_dir="/tmp")
|
| 255 |
+
wb = load_workbook(local, data_only=True)
|
| 256 |
+
sheet = wb.active
|
| 257 |
+
|
| 258 |
+
ma = sheet["BS3"].value
|
| 259 |
+
thiet_bi = sheet["D24"].value
|
| 260 |
+
ngay_ht = sheet["I19"].value
|
| 261 |
+
ngay = ngay_ht.strftime("%Y-%m-%d") if isinstance(ngay_ht, datetime) else str(ngay_ht)
|
| 262 |
+
|
| 263 |
+
ds.append({
|
| 264 |
+
"ma": ma or "Kh么ng r玫",
|
| 265 |
+
"thiet_bi": thiet_bi or "Kh么ng r玫",
|
| 266 |
+
"ngay_ht": ngay
|
| 267 |
+
})
|
| 268 |
+
except:
|
| 269 |
+
continue
|
| 270 |
+
|
| 271 |
+
return ds
|
| 272 |
+
except Exception as e:
|
| 273 |
+
return {"error": str(e)}
|
| 274 |
+
@app.get("/doanh_thu_chi_tiet")
|
| 275 |
+
def doanh_thu_chi_tiet():
|
| 276 |
+
try:
|
| 277 |
+
local_path = hf_hub_download(
|
| 278 |
+
repo_id=REPO_ID,
|
| 279 |
+
repo_type="dataset",
|
| 280 |
+
filename="Theo doi DTNB & DT 2025.xlsx",
|
| 281 |
+
token=HF_TOKEN,
|
| 282 |
+
cache_dir="/tmp"
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
wb = load_workbook(local_path, data_only=True)
|
| 286 |
+
kq = {}
|
| 287 |
+
|
| 288 |
+
for thang in range(1, 13):
|
| 289 |
+
sheet_name = f"Th谩ng {thang}"
|
| 290 |
+
if sheet_name in wb.sheetnames:
|
| 291 |
+
sheet = wb[sheet_name]
|
| 292 |
+
value = sheet["F2"].value
|
| 293 |
+
kq[str(thang)] = value if isinstance(value, (int, float)) else 0
|
| 294 |
+
|
| 295 |
+
return kq
|
| 296 |
+
except Exception as e:
|
| 297 |
+
return {"error": str(e)}
|