#!/usr/bin/env python3 import argparse from pathlib import Path def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("source_dir") parser.add_argument("month", help="YYYY-MM") args = parser.parse_args() year, month = args.month.split("-", 1) month_number = int(month) source_dir = Path(args.source_dir).expanduser() if not source_dir.is_dir(): raise SystemExit(f"供应商汇总目录不存在:{source_dir}") candidates = [] for path in source_dir.rglob("*.xlsx"): name = path.name if name.startswith("~$") or name.startswith(".~"): continue if "供应商汇总表" not in name or "终版" not in name: continue if f"{month_number}月" not in name: continue candidates.append(path) if not candidates: raise SystemExit( f"未找到 {args.month} 的供应商汇总终版表:{source_dir}" ) preferred = [path for path in candidates if year in path.name] selectable = preferred or candidates selected = max(selectable, key=lambda path: path.stat().st_mtime) print(selected) return 0 if __name__ == "__main__": raise SystemExit(main())