Files
blog-writer/bots/article_parser.py
sinmb79 b54f8e198e feat: v3 멀티플랫폼 자동화 엔진 — 변환/배포 엔진 + 쇼츠 + README
## 변환 엔진 (bots/converters/)
- blog_converter: HTML 자동감지 + Schema.org JSON-LD + AdSense 플레이스홀더
- card_converter: Pillow 1080×1080 인스타그램 카드 이미지
- thread_converter: X 스레드 280자 자동 분할
- newsletter_converter: 주간 HTML 뉴스레터
- shorts_converter: TTS + ffmpeg 뉴스앵커 쇼츠 영상 (1080×1920)

## 배포 엔진 (bots/distributors/)
- image_host: ImgBB 업로드 / 로컬 HTTP 서버
- instagram_bot: Instagram Graph API (컨테이너 → 폴링 → 발행)
- x_bot: X API v2 OAuth1 스레드 게시
- tiktok_bot: TikTok Content Posting API v2 청크 업로드
- youtube_bot: YouTube Data API v3 재개가능 업로드

## 기타
- article_parser: KEY_POINTS 파싱 추가 (SNS/TTS용 핵심 3줄)
- publisher_bot: HTML 본문 직접 발행 지원
- scheduler: 시차 배포 스케줄 + Telegram 변환/배포 명령 추가
- remote_claude: Claude Agent SDK Telegram 연동
- templates/shorts_template.json: 코너별 색상/TTS/트랜지션 설정
- scripts/download_fonts.py: NotoSansKR / 맑은고딕 자동 설치
- .gitignore: .claude/, 기획문서, 생성 미디어 파일 추가
- .env.example: 플레이스홀더 텍스트 (실제 값 없음)
- README: v3 아키텍처 전체 문서화 (설치/API키/상세설명/FAQ)
- requirements.txt: openai, pydub 추가

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 18:15:07 +09:00

110 lines
2.8 KiB
Python

"""
article_parser.py
OpenClaw blog-writer 출력(output_format.md 형식)을 파싱하여
발행봇이 사용할 수 있는 dict로 변환.
"""
import re
from typing import Optional
def parse_output(raw_output: str) -> Optional[dict]:
"""
OpenClaw 출력 문자열을 파싱.
Returns: dict 또는 None (파싱 실패 시)
"""
sections = {}
pattern = re.compile(r'---(\w+)---\n(.*?)(?=---\w+---|$)', re.DOTALL)
matches = pattern.findall(raw_output)
for key, value in matches:
sections[key.strip()] = value.strip()
if not sections.get('TITLE') or not sections.get('BODY'):
return None
# 출처 파싱
sources = []
sources_raw = sections.get('SOURCES', '')
for line in sources_raw.splitlines():
line = line.strip()
if not line:
continue
parts = [p.strip() for p in line.split('|')]
sources.append({
'url': parts[0] if len(parts) > 0 else '',
'title': parts[1] if len(parts) > 1 else '',
'date': parts[2] if len(parts) > 2 else '',
})
# 태그 파싱
tags_raw = sections.get('TAGS', '')
tags = [t.strip() for t in tags_raw.split(',') if t.strip()]
# 쿠팡 키워드 파싱
coupang_raw = sections.get('COUPANG_KEYWORDS', '')
coupang_keywords = [k.strip() for k in coupang_raw.split(',') if k.strip()]
# KEY_POINTS 파싱 (변환 엔진용 핵심 3줄)
key_points_raw = sections.get('KEY_POINTS', '')
key_points = []
for line in key_points_raw.splitlines():
line = line.strip().lstrip('•-*').strip()
if line:
key_points.append(line)
key_points = key_points[:3] # 최대 3개
return {
'title': sections.get('TITLE', ''),
'meta': sections.get('META', ''),
'slug': sections.get('SLUG', ''),
'tags': tags,
'corner': sections.get('CORNER', ''),
'body': sections.get('BODY', ''),
'coupang_keywords': coupang_keywords,
'key_points': key_points,
'sources': sources,
'disclaimer': sections.get('DISCLAIMER', ''),
}
if __name__ == '__main__':
sample = """---TITLE---
ChatGPT 처음 쓰는 사람을 위한 완전 가이드
---META---
ChatGPT를 처음 사용하는 분을 위한 단계별 가이드입니다.
---SLUG---
chatgpt-beginners-complete-guide
---TAGS---
ChatGPT, AI, 가이드, 입문
---CORNER---
쉬운세상
---BODY---
## ChatGPT란?
ChatGPT는 OpenAI가 만든 AI 챗봇입니다.
## 어떻게 시작하나요?
1단계: chat.openai.com 접속
## 결론
오늘부터 바로 시작해보세요.
---COUPANG_KEYWORDS---
키보드, 마우스
---SOURCES---
https://openai.com/blog | OpenAI 공식 블로그 | 2026-03-24
---DISCLAIMER---
"""
result = parse_output(sample)
import json
print(json.dumps(result, ensure_ascii=False, indent=2))