- 수집봇: Google Trends, GitHub Trending, HN, Product Hunt, RSS 수집 + 품질 점수(0-100) 시스템 + 6가지 폐기 규칙 - 발행봇: Blogger API v3 자동 발행 + 안전장치(팩트체크/위험키워드) - 링크봇: 쿠팡 파트너스 HMAC 서명 + 자동 링크 삽입 - 분석봇: 색인률/CTR/14일성과 등 5대 핵심 지표 + Telegram 리포트 - 이미지봇: manual/request/auto 3가지 모드 request 모드 — 주기적 프롬프트 전송 → Telegram으로 이미지 수령 - 스케줄러: APScheduler + Telegram 봇 명령 리스너 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
100 lines
2.5 KiB
Python
100 lines
2.5 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()]
|
|
|
|
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,
|
|
'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))
|