# -*- coding: utf-8 -*-
"""공공기관2 몽타주 N 도구 생성(nshot/napply/nbatch 경로 적응)."""
import io, os
D = r"D:\01.프로젝트\DB수집\_스크립트"

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

# 번호폴더 구조 대응: xlsx 경로를 glob로
XLSX_OLD = "xlsx = os.path.join(OUTDIR, f'{name}.xlsx')"
XLSX_NEW = "xlsx = __import__('glob').glob(os.path.join(OUTDIR, f'*.{name}', f'{name}.xlsx'))[0]"
OUTDIR_OLD = r"OUTDIR = r'D:\01.프로젝트\DB수집\공공기관'"
OUTDIR_NEW = r"OUTDIR = r'D:\01.프로젝트\DB수집\작업파일\공공기관2'"

transform("_공공기관_nshot.py", "_공공기관2_nshot.py", [(OUTDIR_OLD, OUTDIR_NEW), (XLSX_OLD, XLSX_NEW)])
transform("_공공기관_napply.py", "_공공기관2_napply.py", [(OUTDIR_OLD, OUTDIR_NEW), (XLSX_OLD, XLSX_NEW)])

# nbatch: 모듈/probe 경로
transform("_공공기관_nbatch.py", "_공공기관2_nbatch.py", [
    ("_공공기관_nshot", "_공공기관2_nshot"),
    ("_공공기관_napply", "_공공기관2_napply"),
    ("_공공기관_probe.json", "_공공기관2_probe.json"),
])
print("done")
