# -*- coding: utf-8 -*-
"""공공기관2 배치용 probe/phase1/phase234 스크립트 생성 (경로만 치환)."""
import io, os

D = r"D:\01.프로젝트\DB수집\_스크립트"

def transform(src_name, dst_name, repls):
    src = io.open(os.path.join(D, src_name), encoding="utf-8").read()
    for a, b in repls:
        if a not in src:
            print("  [warn] 패턴 못찾음:", repr(a[:60]))
        src = src.replace(a, b)
    io.open(os.path.join(D, dst_name), "w", encoding="utf-8").write(src)
    print("생성:", dst_name)

# probe: STATUS + 출력 json
transform("_공공기관_probe.py", "_공공기관2_probe.py", [
    (r"작업파일\공공기관_작업현황.xlsx", r"작업파일\공공기관2\공공기관2_작업현황.xlsx"),
    ("_공공기관_probe.json", "_공공기관2_probe.json"),
])

# phase1: OUTDIR(번호폴더구조) + PROBE json + 출력경로 번호폴더
transform("_공공기관_phase1.py", "_공공기관2_phase1.py", [
    (r"OUTDIR = r'D:\01.프로젝트\DB수집\공공기관'",
     r"OUTDIR = r'D:\01.프로젝트\DB수집\작업파일\공공기관2'"),
    ("_공공기관_probe.json", "_공공기관2_probe.json"),
    ("output = os.path.join(OUTDIR, f'{name}.xlsx')",
     "output = os.path.join(OUTDIR, f'{num}.{name}', f'{name}.xlsx')"),
])

# phase234: OUTDIR + PROBE json + 입력경로 번호폴더
transform("_공공기관_phase234.py", "_공공기관2_phase234.py", [
    (r"OUTDIR = r'D:\01.프로젝트\DB수집\공공기관'",
     r"OUTDIR = r'D:\01.프로젝트\DB수집\작업파일\공공기관2'"),
    ("_공공기관_probe.json", "_공공기관2_probe.json"),
    ("xlsx = os.path.join(OUTDIR, f'{name}.xlsx')",
     "xlsx = os.path.join(OUTDIR, f'{num}.{name}', f'{name}.xlsx')"),
])
print("done")
