"""Generate versioned presentation copy directly from the approved reference.""" import json import re from pathlib import Path root = Path(__file__).resolve().parents[1] text = (root / 'reference/AI测肤报告页话术修改.md').read_text() text = re.sub(r'\\([.{}_&-])', r'\1', text) keys = ['contour', 'wrinkles', 'color', 'smooth', 'water', 'sens', 'acne'] data = {'version': '2026-10-09', 'conclusion': {}, 'care': {}} section, key = None, None for line in text.splitlines(): heading = re.match(r'#### ([56])\.(\d)', line) if heading: section = 'conclusion' if heading[1] == '5' else 'care' key = keys[int(heading[2]) - 1] data[section][key] = {} conclusion = re.match(r'\*\*【(改善|良好|优秀)】\*\*\s*(.+)', line) care = re.match(r'【(改善|良好|优秀)·(护理|生活方式)】\s*(.+)', line) if section == 'conclusion' and conclusion: data[section][key][conclusion[1]] = conclusion[2].strip() if section == 'care' and care: data[section][key].setdefault(care[1], {})['care' if care[2] == '护理' else 'lifestyle'] = care[3].strip() for category in keys: assert len(data['conclusion'][category]) == len(data['care'][category]) == 3 payload = json.dumps(data, ensure_ascii=False, indent=2) (root / 'h5/js/report-copy.js').write_text( '// Generated from reference/AI测肤报告页话术修改.md; run tools/build_report_copy.py.\n' '(function(root,factory){if(typeof module==="object"&&module.exports)module.exports=factory();else root.ReportCopy=factory();})(typeof window!=="undefined"?window:this,function(){return ' + payload + ';});\n')