diff --git a/batch.py b/batch.py index 2afb59b..ff819c9 100644 --- a/batch.py +++ b/batch.py @@ -115,9 +115,22 @@ def read_xlsx_xml(path: str, max_rows: int = 50) -> dict: def extract_zip(zip_path: str, dest_dir: str) -> list[str]: - """Extract zip and return list of xlsx files.""" + """Extract zip and return list of xlsx files. + + Handles Cyrillic filenames: Python's zipfile decodes names as CP437 + when the UTF-8 flag is not set. We detect and fix this. + """ with zipfile.ZipFile(zip_path) as z: - z.extractall(dest_dir) + for info in z.infolist(): + # Fix Cyrillic filenames: if flag bit 11 is not set, + # Python decodes as CP437 — re-encode and decode as UTF-8 + if not (info.flag_bits & 0x800): + try: + fixed = info.filename.encode('cp437').decode('utf-8') + info.filename = fixed + except (UnicodeDecodeError, UnicodeEncodeError): + pass # keep original if re-decode fails + z.extract(info, dest_dir) files = [] for f in Path(dest_dir).rglob('*.xlsx'): if not f.name.startswith('~$'):