Files
JJOllamaManager/wiki/tools/ppt_watch.py
Claude fd84a6d776 위키 볼트를 wiki 폴더로: 위키 파일을 wiki/ 안으로 모음
- wiki/ 안으로 옮김: .obsidian, raw, assets, tools, CLAUDE.md, PROJECT.md
- 맨 위 CLAUDE.md 는 `@wiki/CLAUDE.md` 한 줄 (Claude Code 자동 참조용)
- 맨 위에 남김: .claude (Claude Code), README.md (Gitea 첫 화면), 프로그램 파일
- wiki/tools 도구 기준 폴더를 wiki 로, .claude 명령·.gitignore·문서 속 경로 갱신
- wiki/.obsidian/app.json: 볼트 밖이 된 폴더 제외 목록 삭제
- 작업현황·변경기록·지시기록 갱신 (v2.1.0, d1a8009 포함)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HnDmXrFqktWwYa1cuJRAVZ
2026-11-03 09:10:20 +00:00

107 lines
4.7 KiB
Python

"""PPT 변경 감지 → PNG 자동 재생성 → 위키(화면설명.md / 장표설명.md) 자동 반영.
대상: wiki/08_화면/**/*.pptx, wiki/07_제안서/**/*.pptx
사용: python tools/ppt_watch.py (계속 감시, 5초 간격)
python tools/ppt_watch.py --once (한 번만 검사)
변환: Windows = PowerPoint(설치 시) → 없으면 LibreOffice / Mac·Linux = LibreOffice + pdftoppm
필요: pip install python-pptx (Windows PowerPoint 사용 시 pip install pywin32)"""
import sys, os, time, json, hashlib, pathlib, subprocess, shutil, tempfile, datetime, re
ROOT = pathlib.Path(__file__).resolve().parent.parent # = wiki 폴더 (볼트)
TARGETS = [ROOT / "08_화면", ROOT / "07_제안서"]
STATE = ROOT / "tools" / ".ppt_state.json"
KST = datetime.timezone(datetime.timedelta(hours=9))
A, B = "<!-- PPT-AUTO-START -->", "<!-- PPT-AUTO-END -->"
def digest(p):
return hashlib.sha1(p.read_bytes()).hexdigest()
def png_name(pptx, i):
return pptx.with_name(f"{pptx.stem}.png" if i == 1 else f"{pptx.stem}_{i:02d}.png")
def to_png_powerpoint(pptx):
import win32com.client # pywin32
app = win32com.client.Dispatch("PowerPoint.Application")
pres = app.Presentations.Open(str(pptx), WithWindow=False)
try:
for i, s in enumerate(pres.Slides, 1):
s.Export(str(png_name(pptx, i)), "PNG", 1600, 900)
finally:
pres.Close()
def soffice():
for c in ("soffice", "libreoffice", r"C:\Program Files\LibreOffice\program\soffice.exe",
"/Applications/LibreOffice.app/Contents/MacOS/soffice"):
if shutil.which(c) or os.path.exists(c): return shutil.which(c) or c
raise RuntimeError("LibreOffice 가 필요합니다")
def to_png_libreoffice(pptx):
with tempfile.TemporaryDirectory() as t:
subprocess.run([soffice(), "--headless", "--convert-to", "pdf", "--outdir", t, str(pptx)],
check=True, capture_output=True)
pdf = pathlib.Path(t) / f"{pptx.stem}.pdf"
subprocess.run(["pdftoppm", "-png", "-r", "110", str(pdf), str(pathlib.Path(t) / "s")], check=True)
for i, f in enumerate(sorted(pathlib.Path(t).glob("s-*.png")), 1):
shutil.move(str(f), png_name(pptx, i))
def to_png(pptx):
for old in pptx.parent.glob(f"{pptx.stem}*.png"):
old.unlink()
if os.name == "nt":
try:
return to_png_powerpoint(pptx)
except Exception:
pass
to_png_libreoffice(pptx)
def slide_texts(pptx):
from pptx import Presentation
out = []
for i, s in enumerate(Presentation(str(pptx)).slides, 1):
t = [sh.text_frame.text.strip() for sh in s.shapes if sh.has_text_frame and sh.text_frame.text.strip()]
out.append((i, t))
return out
def update_wiki(pptx):
md = pptx.parent / ("화면설명.md" if "08_화면" in pptx.parts else f"{pptx.stem}_장표설명.md")
body = md.read_text(encoding="utf-8") if md.exists() else f"---\nstatus: 초안\n---\n# {pptx.stem}\n"
lines = [A, f"## PPT 내용 (자동 추출 — {pptx.name})"]
for i, t in slide_texts(pptx):
lines.append(f"### 슬라이드 {i}\n![[{png_name(pptx, i).name}]]")
lines += [f"- {x.replace(chr(10), ' / ')}" for x in t]
lines.append(B)
block = "\n".join(lines)
body = re.sub(re.escape(A) + ".*?" + re.escape(B), block, body, flags=re.S) if A in body else body.rstrip() + "\n\n" + block + "\n"
now = datetime.datetime.now(KST)
if "## 수정 이력" not in body:
body += "\n## 수정 이력\n"
body = body.rstrip() + f"\n- {now:%Y-%m-%d %H:%M} PPT 변경 감지 → 이미지·내용 자동 갱신 (검토 필요)\n"
body = re.sub(r"^status:\s*컨펌", "status: 검토중", body, flags=re.M) # 컨펌 후 바뀌면 재검토
md.write_text(body, encoding="utf-8")
def scan(state):
changed = []
for base in TARGETS:
for p in base.rglob("*.pptx"):
if p.name.startswith("~$"): continue
h = digest(p); k = p.relative_to(ROOT).as_posix()
if state.get(k) != h:
try:
to_png(p); update_wiki(p); state[k] = h; changed.append(k)
print("갱신:", k)
except Exception as e:
print("실패:", k, e)
if changed:
STATE.write_text(json.dumps(state, ensure_ascii=False, indent=1), encoding="utf-8")
subprocess.run([sys.executable, str(ROOT / "tools" / "build_menu.py")])
return changed
def main():
state = json.loads(STATE.read_text(encoding="utf-8")) if STATE.exists() else {}
if "--once" in sys.argv:
scan(state); return
print("PPT 감시 중... (Ctrl+C 종료)")
while True:
scan(state); time.sleep(5)
if __name__ == "__main__":
main()