Debug: Add detailed logging for analysis pipeline

This commit is contained in:
Remora
2026-02-09 19:11:34 +01:00
parent e4421d7bc9
commit e42e5ca563

21
bot.py
View File

@@ -161,6 +161,8 @@ def fetch_url_content(url):
def analyze_content(url, title, content, link_type):
"""Analyze content and suggest summary + tag locally"""
logger.debug(f" 🤖 Analyzing content: {url}")
logger.debug(f" Content length: {len(content)} chars")
logger.debug(f" Link type: {link_type}")
try:
# Extract useful info from HTML content
@@ -170,12 +172,14 @@ def analyze_content(url, title, content, link_type):
desc_match = re.search(r'<meta\s+name="description"\s+content="([^"]+)"', content, re.IGNORECASE)
if desc_match:
description = desc_match.group(1).strip()
logger.debug(f" Found meta description: {description[:80]}")
# Looking for og:description
if not description:
og_desc = re.search(r'<meta\s+property="og:description"\s+content="([^"]+)"', content, re.IGNORECASE)
if og_desc:
description = og_desc.group(1).strip()
logger.debug(f" Found og:description: {description[:80]}")
# Looking for first paragraph after title
if not description:
@@ -225,16 +229,20 @@ def analyze_content(url, title, content, link_type):
# Truncate summary to reasonable length
summary = summary[:200]
logger.debug(f" ✓ Tag: {tag}, Summary: {summary[:80]}")
logger.info(f" Analysis complete - Tag: {tag}, Summary: {summary[:60]}")
return {
result = {
"summary": summary,
"tag": tag,
"relevance": "relevant"
}
logger.debug(f" Returning: {result}")
return result
except Exception as e:
logger.error(f" Analysis error: {e}")
import traceback
logger.error(traceback.format_exc())
# Return minimal analysis
return {
"summary": title,
@@ -325,8 +333,14 @@ class LinkAnalyzerBot(discord.Client):
# Analyze content if fetch was successful
analysis_data = None
logger.debug(f" 📊 Fetch status: {fetch_result['status']}")
if fetch_result["status"] == "ok":
logger.debug(f" 🔍 Starting analysis...")
analysis_data = analyze_content(url, title, fetch_result.get("content", ""), link_type)
logger.debug(f" Analysis result: {analysis_data}")
else:
logger.debug(f" ⚠️ Fetch failed, skipping analysis")
# Prepare summary for Tududi
summary_text = ""
@@ -334,6 +348,9 @@ class LinkAnalyzerBot(discord.Client):
if analysis_data:
summary_text = analysis_data.get("summary", "")
tag = analysis_data.get("tag", "interesting")
logger.debug(f" ✓ Got summary: {summary_text[:80]}")
else:
logger.warning(f" ❌ No analysis data returned")
# Add to Tududi with summary
tududi_ok = add_to_tududi(title, url, link_type, summary_text, tag)