Debug: Add detailed logging for analysis pipeline
This commit is contained in:
21
bot.py
21
bot.py
@@ -161,6 +161,8 @@ def fetch_url_content(url):
|
|||||||
def analyze_content(url, title, content, link_type):
|
def analyze_content(url, title, content, link_type):
|
||||||
"""Analyze content and suggest summary + tag locally"""
|
"""Analyze content and suggest summary + tag locally"""
|
||||||
logger.debug(f" 🤖 Analyzing content: {url}")
|
logger.debug(f" 🤖 Analyzing content: {url}")
|
||||||
|
logger.debug(f" Content length: {len(content)} chars")
|
||||||
|
logger.debug(f" Link type: {link_type}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Extract useful info from HTML content
|
# 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)
|
desc_match = re.search(r'<meta\s+name="description"\s+content="([^"]+)"', content, re.IGNORECASE)
|
||||||
if desc_match:
|
if desc_match:
|
||||||
description = desc_match.group(1).strip()
|
description = desc_match.group(1).strip()
|
||||||
|
logger.debug(f" Found meta description: {description[:80]}")
|
||||||
|
|
||||||
# Looking for og:description
|
# Looking for og:description
|
||||||
if not description:
|
if not description:
|
||||||
og_desc = re.search(r'<meta\s+property="og:description"\s+content="([^"]+)"', content, re.IGNORECASE)
|
og_desc = re.search(r'<meta\s+property="og:description"\s+content="([^"]+)"', content, re.IGNORECASE)
|
||||||
if og_desc:
|
if og_desc:
|
||||||
description = og_desc.group(1).strip()
|
description = og_desc.group(1).strip()
|
||||||
|
logger.debug(f" Found og:description: {description[:80]}")
|
||||||
|
|
||||||
# Looking for first paragraph after title
|
# Looking for first paragraph after title
|
||||||
if not description:
|
if not description:
|
||||||
@@ -225,16 +229,20 @@ def analyze_content(url, title, content, link_type):
|
|||||||
# Truncate summary to reasonable length
|
# Truncate summary to reasonable length
|
||||||
summary = summary[:200]
|
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,
|
"summary": summary,
|
||||||
"tag": tag,
|
"tag": tag,
|
||||||
"relevance": "relevant"
|
"relevance": "relevant"
|
||||||
}
|
}
|
||||||
|
logger.debug(f" Returning: {result}")
|
||||||
|
return result
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Analysis error: {e}")
|
logger.error(f" Analysis error: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
# Return minimal analysis
|
# Return minimal analysis
|
||||||
return {
|
return {
|
||||||
"summary": title,
|
"summary": title,
|
||||||
@@ -325,8 +333,14 @@ class LinkAnalyzerBot(discord.Client):
|
|||||||
|
|
||||||
# Analyze content if fetch was successful
|
# Analyze content if fetch was successful
|
||||||
analysis_data = None
|
analysis_data = None
|
||||||
|
logger.debug(f" 📊 Fetch status: {fetch_result['status']}")
|
||||||
|
|
||||||
if fetch_result["status"] == "ok":
|
if fetch_result["status"] == "ok":
|
||||||
|
logger.debug(f" 🔍 Starting analysis...")
|
||||||
analysis_data = analyze_content(url, title, fetch_result.get("content", ""), link_type)
|
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
|
# Prepare summary for Tududi
|
||||||
summary_text = ""
|
summary_text = ""
|
||||||
@@ -334,6 +348,9 @@ class LinkAnalyzerBot(discord.Client):
|
|||||||
if analysis_data:
|
if analysis_data:
|
||||||
summary_text = analysis_data.get("summary", "")
|
summary_text = analysis_data.get("summary", "")
|
||||||
tag = analysis_data.get("tag", "interesting")
|
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
|
# Add to Tududi with summary
|
||||||
tududi_ok = add_to_tududi(title, url, link_type, summary_text, tag)
|
tududi_ok = add_to_tududi(title, url, link_type, summary_text, tag)
|
||||||
|
|||||||
Reference in New Issue
Block a user