fix: 발행 완료된 글감을 /collect, /write 목록에서 제외
- publish() 성공 시 topics/ 에서 해당 topic 파일 자동 삭제 - /write, /collect 목록에 발행 제목 유사도 80% 필터 추가 - _load_published_titles(), _filter_unpublished() 헬퍼 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -734,6 +734,9 @@ async def cmd_collect(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
topics_dir = DATA_DIR / 'topics'
|
||||
today = datetime.now().strftime('%Y%m%d')
|
||||
files = sorted(topics_dir.glob(f'{today}_*.json'))
|
||||
# 이미 발행된 글감 제외
|
||||
published_titles = _load_published_titles()
|
||||
files = _filter_unpublished(files, published_titles)
|
||||
if not files:
|
||||
await update.message.reply_text("✅ 수집 완료! 오늘 수집된 글감이 없습니다.")
|
||||
return
|
||||
@@ -759,10 +762,49 @@ async def cmd_collect(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await update.message.reply_text(f"❌ 수집 오류: {e}")
|
||||
|
||||
|
||||
def _load_published_titles() -> set[str]:
|
||||
"""발행 이력에서 제목 set 로드 (빠른 필터링용)"""
|
||||
titles = set()
|
||||
published_dir = DATA_DIR / 'published'
|
||||
if not published_dir.exists():
|
||||
return titles
|
||||
for f in published_dir.glob('*.json'):
|
||||
try:
|
||||
data = json.loads(f.read_text(encoding='utf-8'))
|
||||
if 'title' in data:
|
||||
titles.add(data['title'])
|
||||
except Exception:
|
||||
pass
|
||||
return titles
|
||||
|
||||
|
||||
def _filter_unpublished(files: list, published_titles: set) -> list:
|
||||
"""이미 발행된 글감 파일 제외"""
|
||||
from difflib import SequenceMatcher
|
||||
result = []
|
||||
for f in files:
|
||||
try:
|
||||
data = json.loads(f.read_text(encoding='utf-8'))
|
||||
topic = data.get('topic', '')
|
||||
# 발행 제목과 유사도 80% 이상이면 제외
|
||||
is_published = any(
|
||||
SequenceMatcher(None, topic, t).ratio() >= 0.8
|
||||
for t in published_titles
|
||||
)
|
||||
if not is_published:
|
||||
result.append(f)
|
||||
except Exception:
|
||||
result.append(f)
|
||||
return result
|
||||
|
||||
|
||||
async def cmd_write(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
topics_dir = DATA_DIR / 'topics'
|
||||
today = datetime.now().strftime('%Y%m%d')
|
||||
files = sorted(topics_dir.glob(f'{today}_*.json'))
|
||||
# 이미 발행된 글감 제외
|
||||
published_titles = _load_published_titles()
|
||||
files = _filter_unpublished(files, published_titles)
|
||||
if not files:
|
||||
await update.message.reply_text("오늘 수집된 글감이 없습니다. /collect 먼저 실행하세요.")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user