Files
Aislo/resources/knowledge/original/_pipeline/extract_zip.py
T
eomsangdonandClaude Fable 5 81cd7e23c3 feat(knowledge): 도메인 지식저장소 메인 통합 + resources 그룹 체계 재편
knowledge (구 Aislo-law 독립 저장소 → resources/knowledge 이관, 저장소 폐지):
- 법령·행정규칙·표준시방서·교본 원문 + 기술문서 55건 + 실무 분석·종합비교
- 루트 지침 체계: README(지도)·00_운영지침·01_수집지침·02_분석지침·
  03_미결_및_확인사항(교본 충돌 리스트 포함)·04_참조_법령기준_목록
- 기술문서 55건 원문 전수 검증 완료 (사방 설계홍수량 법정 기준 등 반영)
- 정리: CAD·오피스 잔재 142건, 중복 zip 7건(413MB), 빈 폴더 30개 제거

resources 그룹 재편 (이름순 그룹핑):
- app_branding(구 prog_icon.jpg)·app_policies(구 legal)·
  data_global_contours(구 grobal_contours)·data_rainfall_idf_cache(구 wamis_contours)·
  template_2dDrawing(구 dwg_analysis/templete — 오타 교정, 상수·경로 동기화)
- dwg_analysis(분석 완료 1.8GB)·templates(빈 폴더)·templete_calc_cost.xlsx 삭제
- 참조 코드 5파일 경로 수정 + 프론트 재빌드 (구 경로 잔존 0)
- .gitignore: resources 추적 전환, national_contours.gpkg(22GB) 영구 제외
- .env: knowledge 수집용 API 정보 주석 통합 (KCSC·법령센터·조달청 제비율)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-12 19:14:32 +09:00

69 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""첨부 zip 압축해제 + 문서화.
- zip 내 CP949(EUC-KR) 파일명 mojibake를 복원해 `첨부/[zip]<이름>/` 에 해제
- 내부 HWP/HWPX → md 변환(hwpx_text.to_md / hwp5_to_md)
"""
import re, sys, zipfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import hwpx_text
ROOT = Path(__file__).resolve().parent.parent
def fixname(n):
"""zip 엔트리명 CP437 mojibake → CP949 복원."""
try:
return n.encode("cp437").decode("cp949")
except Exception:
return n
def safe_part(s):
return re.sub(r'[:*?"<>|]', "_", s).strip()
def extract_one(zip_path):
zf = zipfile.ZipFile(zip_path)
dest = zip_path.parent / ("[압축] " + zip_path.stem)
dest.mkdir(exist_ok=True)
n = 0
for info in zf.infolist():
if info.is_dir():
continue
rel = "/".join(safe_part(p) for p in fixname(info.filename).split("/"))
out = dest / rel
out.parent.mkdir(parents=True, exist_ok=True)
with zf.open(info) as src:
out.write_bytes(src.read())
n += 1
return dest, n
def convert_dir(folder):
ok = fail = 0
for f in sorted(folder.rglob("*")):
if f.suffix.lower() not in (".hwp", ".hwpx"):
continue
md = f.with_suffix(".md")
try:
b = f.read_bytes()[:4]
if b[:2] == b"PK": # HWPX
text = hwpx_text.to_md(f)
elif b.hex() == "d0cf11e0": # 구형 HWP
text = hwpx_text.hwp5_to_md(f)
else:
fail += 1
continue
md.write_text(text, encoding="utf-8")
ok += 1
except Exception as e:
print(f" ! {f.name[:50]} :: {type(e).__name__}")
fail += 1
return ok, fail
if __name__ == "__main__":
zips = [Path(a) for a in sys.argv[1:]] or list(ROOT.rglob("첨부/*.zip"))
for z in zips:
dest, n = extract_one(z)
ok, fail = convert_dir(dest)
print(f"[{z.name}] 해제 {n} / md {ok} 실패 {fail}{dest.name}")