From ac0678d9c24bf4ac37512320a8f0a0815546e7bb Mon Sep 17 00:00:00 2001 From: dsutanto Date: Thu, 30 Jul 2026 21:01:56 +0700 Subject: [PATCH] Batch number from file --- recounting_dashboard.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/recounting_dashboard.py b/recounting_dashboard.py index 0ce5458..7efe23b 100644 --- a/recounting_dashboard.py +++ b/recounting_dashboard.py @@ -41,7 +41,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", re.IGNORECASE) +_FILENAME_RE = re.compile(r"batch[_-]?(\d+)", re.IGNORECASE) _streaming_mp4 = None _streaming_lock = threading.Lock() @@ -50,12 +50,9 @@ _current_file = None def _parse_filename(filename): - m = _FILENAME_RE.match(filename) + m = _FILENAME_RE.search(filename) if m: - batch_num = int(m.group(1)) - date_str = m.group(2) - date_formatted = f"{date_str[:4]}-{date_str[4:6]}-{date_str[6:8]}" - return batch_num, date_formatted + return int(m.group(1)), None return None, None @@ -220,7 +217,9 @@ def api_batch_result(): if batch_num is None: return jsonify({"success": False, "error": "Cannot parse batch number from filename"}), 200 - date_str = _folder_date(fpath) or _parse_filename(filename)[1] + date_str = _folder_date(fpath) + if not date_str: + return jsonify({"success": False, "error": "Cannot determine date from folder"}), 200 def _match_in_batches(batches): for b in batches: