Live Counter get total count per batch 3

This commit is contained in:
proitlab committed 2026-07-29 14:36:29 +07:00
1 parent cc807d3b8b
commit 1a3f6ffb6f
2 files changed
+38 -10

No files matched your search

+24 -7
View File
@@ -35,7 +35,7 @@ FLASK_DEBUG = os.getenv("FLASK_DEBUG", "false").lower() == "true"
_http_session = requests.Session()
_http_session.timeout = 3
_FILENAME_RE = re.compile(r"batch_(\d+)_(\d{8})_\d{6}\.mp4")
_FILENAME_RE = re.compile(r"batch[_-](\d+)[_-](\d{8})[_-]\d{6}\.mp4", re.IGNORECASE)
def _parse_filename(filename):
@@ -128,12 +128,16 @@ def api_batch_result():
if batch_num is None:
return jsonify({"success": False, "error": "Cannot parse batch number from filename"}), 200
data = _api_get(LIVE_API_URL, f"/api/day-detail/{date_str}")
if not data:
return jsonify({"success": False, "error": "Live API unreachable"}), 200
def _match_in_batches(batches):
for b in batches:
if b.get("batch_number") == batch_num:
return b
return None
for b in data.get("batches", []):
if b.get("batch_number") == batch_num:
data = _api_get(LIVE_API_URL, f"/api/day-detail/{date_str}")
if data:
b = _match_in_batches(data.get("batches", []))
if b:
return jsonify({
"success": True,
"batch_number": batch_num,
@@ -143,7 +147,20 @@ def api_batch_result():
"end_time": b.get("end_time"),
})
return jsonify({"success": False, "error": f"Batch #{batch_num} not found on {date_str}"}), 200
recent = _api_get(LIVE_API_URL, "/api/recent-batches?limit=100")
if recent:
for entry in recent if isinstance(recent, list) else recent.get("batches", []):
if isinstance(entry, dict) and entry.get("batch_number") == batch_num:
return jsonify({
"success": True,
"batch_number": batch_num,
"date": entry.get("date", date_str),
"count": entry["count"],
"start_time": entry.get("start_time"),
"end_time": entry.get("end_time"),
})
return jsonify({"success": False, "error": f"Batch #{batch_num} not found"}), 200
@app.route("/api/stop-recount", methods=["POST"])