refactor: 아웃바운드 메일·보고서·소개서의 병원 목록·소개서 버전·실측일을 인자와 실측 데이터로 받는다
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e41bc218c
commit
d64a19ae9f
4 files changed
+60
-25
No files matched your search
@@ -6,10 +6,14 @@
|
||||
- 효과는 약속하지 않는다: "인용할 수 있는 근거가 생긴다", "다시 측정해 보여 드린다" 까지만 쓴다
|
||||
- 서명은 넣지 않는다 (발송인이 직접 추가)
|
||||
|
||||
python3 docs/reports/outbound_webforai/build_mail_drafts.py <출력 json> [--images=<소개서 폴더>,<이미지 폴더>] [--roadmap=<이미지 폴더>]
|
||||
python3 docs/reports/outbound_webforai/build_mail_drafts.py <출력 json> --clinics=<병원>,<병원>,...
|
||||
[--images=<소개서 폴더>,<이미지 폴더>] [--roadmap=<이미지 폴더>]
|
||||
|
||||
- 메일 이미지용 소개서는 소개서 폴더에서 병원별 가장 높은 버전(WebforAI_소개서_{병원}_v{N}_*.pptx)을 고른다
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@@ -17,8 +21,6 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import build_diagnosis_report as report # noqa: E402
|
||||
import run_outbound_probe as probe # noqa: E402
|
||||
|
||||
CLINICS = ["그랜드성형외과", "JK성형외과", "아이디병원", "바노바기성형외과", "원진성형외과"]
|
||||
|
||||
# 문제 제기에 쓰는 환자 질문 (핵심 발견 질문을 환자 말투로)
|
||||
ASK = {"kr:Q2": "“강남 {proc} 잘하는 곳 추천해줘”", "kr:Q3": "“강남 성형외과 추천해줘”",
|
||||
"en:Q4": "“English-speaking plastic surgeon in Seoul”"}
|
||||
@@ -44,7 +46,9 @@ def body(d, clinic):
|
||||
"""친절하고 간결한 본문. 세부 수치는 이미지(핵심 발견·로드맵)와 첨부 PDF 가 맡는다."""
|
||||
name, kf = d["name"], d["kf"]
|
||||
neun, reul = report.josa(name, "은", "는"), report.josa(name, "을", "를")
|
||||
ask = ASK[kf["slot"]].format(proc=clinic["procedure_ko"])
|
||||
lang, qno = kf["slot"].split(":Q")
|
||||
ask = (ASK[kf["slot"]].format(proc=clinic["procedure_ko"]) if kf["slot"] in ASK
|
||||
else f"“{d['questions'][lang][int(qno) - 1]['question']}”")
|
||||
who = "해외 환자" if kf["slot"].startswith("en") else "환자"
|
||||
fails = [t for t, ok, _ in d["site"] if not ok]
|
||||
causes = [CAUSE_PLAIN.get(t, t) for t in CAUSE_ORDER if t in fails][:3]
|
||||
@@ -74,18 +78,30 @@ def body(d, clinic):
|
||||
MAIL_HERO = "AI 추천 목록에는 아직 없었습니다." # 소개서의 "한 번도 언급되지 않았습니다." 를 메일용으로 순화
|
||||
|
||||
|
||||
def images(deck_dir, img_dir):
|
||||
def latest_deck(deck_dir, name):
|
||||
"""소개서 폴더에서 이 병원의 가장 높은 버전 소개서. 같은 버전이 둘이면 멈춘다."""
|
||||
rx = re.compile(r"WebforAI_소개서_" + re.escape(name) + r"_v(\d+)_.*\.pptx$")
|
||||
found = [(int(m.group(1)), f) for f in os.listdir(deck_dir) if not f.startswith("~$") and (m := rx.match(f))]
|
||||
assert found, f"소개서 없음: {name} ({deck_dir})"
|
||||
top = max(v for v, _ in found)
|
||||
files = [f for v, f in found if v == top]
|
||||
assert len(files) == 1, f"같은 버전 소개서가 여럿입니다: {files}"
|
||||
return os.path.join(deck_dir, files[0])
|
||||
|
||||
|
||||
def images(clinics, deck_dir, img_dir):
|
||||
"""소개서 4장(핵심 발견)을 메일 본문용 PNG(가로 1600px)로 뽑는다.
|
||||
메일용은 강조 문장을 순화하고 쪽 번호(03 · Key Finding)를 뺀다. 소개서 원본은 건드리지 않는다."""
|
||||
from pptx import Presentation
|
||||
import tempfile
|
||||
os.makedirs(img_dir, exist_ok=True)
|
||||
tmp = tempfile.mkdtemp()
|
||||
for name in CLINICS:
|
||||
for name in clinics:
|
||||
out = os.path.join(img_dir, f"{name}_핵심발견")
|
||||
assert not os.path.exists(out + ".png"), f"이미 있습니다: {out}.png"
|
||||
ver = "v14" if name == "그랜드성형외과" else "v13"
|
||||
prs = Presentation(os.path.join(deck_dir, f"WebforAI_소개서_{name}_{ver}_2026-10-26.pptx"))
|
||||
deck = latest_deck(deck_dir, name)
|
||||
print("소개서:", os.path.basename(deck))
|
||||
prs = Presentation(deck)
|
||||
s4 = prs.slides[3]
|
||||
hero = next(sh for sh in s4.shapes if sh.name == "TextBox 2")
|
||||
assert hero.text_frame.paragraphs[2].runs[0].text == "한 번도 언급되지 않았습니다."
|
||||
@@ -190,11 +206,11 @@ def roadmap_html(d, logos):
|
||||
'<div class="top"><div><div class="eyebrow">AI DISCOVERY · %s</div><h1>AI 답변 진단에서 <em>개선까지</em></h1></div>'
|
||||
'<div class="logos"><img src="%s"><div class="bar"></div><img src="%s" style="height:22px"></div></div>'
|
||||
'<div class="flow">%s</div>'
|
||||
'<div class="foot">측정 2026. 10. 19 · 10. 26 · 질문 10개 × AI 답변엔진 4종 × 3회 · 응답 점수는 판정 가능한 답변 중 언급·인용 횟수, 홈페이지 점검은 12개 항목 중 충족 수</div>'
|
||||
'</body></html>' % (ROADMAP_CSS, H.escape(name), logos[0], logos[1], cards))
|
||||
'<div class="foot">측정 %s · 질문 10개 × AI 답변엔진 4종 × 3회 · 응답 점수는 판정 가능한 답변 중 언급·인용 횟수, 홈페이지 점검은 12개 항목 중 충족 수</div>'
|
||||
'</body></html>' % (ROADMAP_CSS, H.escape(name), logos[0], logos[1], cards, d["measured"]))
|
||||
|
||||
|
||||
def roadmap_images(img_dir):
|
||||
def roadmap_images(names, img_dir):
|
||||
from playwright.sync_api import sync_playwright
|
||||
a = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
|
||||
logos = [report.b64(f"{a}/infinith_white.png"), report.b64(f"{a}/webforai_white.png")]
|
||||
@@ -204,7 +220,7 @@ def roadmap_images(img_dir):
|
||||
with sync_playwright() as p:
|
||||
b = p.chromium.launch()
|
||||
pg = b.new_page(viewport={"width": 1600, "height": 900}, device_scale_factor=1)
|
||||
for name in CLINICS:
|
||||
for name in names:
|
||||
out = os.path.join(img_dir, f"{name}_AI_Discovery_로드맵.png")
|
||||
assert not os.path.exists(out), f"이미 있습니다: {out}"
|
||||
c = next(x for x in clinics if x["name"] == name)
|
||||
@@ -218,11 +234,11 @@ def roadmap_images(img_dir):
|
||||
b.close()
|
||||
|
||||
|
||||
def main(out_json):
|
||||
def main(out_json, names):
|
||||
clinics = probe.load("pilot_clinics.json")
|
||||
_, plan = probe.expand(clinics, probe.load("question_template.json"))
|
||||
res = {}
|
||||
for name in CLINICS:
|
||||
for name in names:
|
||||
c = next(x for x in clinics if x["name"] == name)
|
||||
b = body(report.report_data(c, plan), c)
|
||||
banned = ["브릿지", "bridge", "doorway", "서포터즈", "장악", "주입", "노출", "—", "보장", "반드시"]
|
||||
@@ -233,9 +249,10 @@ def main(out_json):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1])
|
||||
for a in sys.argv[2:]:
|
||||
if a.startswith("--images="):
|
||||
images(*a.split("=", 1)[1].split(","))
|
||||
if a.startswith("--roadmap="):
|
||||
roadmap_images(a.split("=", 1)[1])
|
||||
opts = dict(a[2:].split("=", 1) for a in sys.argv[2:])
|
||||
names = opts["clinics"].split(",")
|
||||
main(sys.argv[1], names)
|
||||
if "images" in opts:
|
||||
images(names, *opts["images"].split(","))
|
||||
if "roadmap" in opts:
|
||||
roadmap_images(names, opts["roadmap"])
|
||||
Reference in new issue
Block a user