- Job history tracking with SQLite table - Dry-run mode (--dry-run) to test scrape rules - Plugin system with 3 built-in plugins (sentiment, dedupe, keywords) - REST API server (--api) for Metabase/Grafana integration - Parquet export (--export-parquet) for DuckDB/warehouses - SQLite maintenance (--backup, --vacuum) - Dashboard Integrations tab with external tools guides - Updated Dockerfile and docker-compose.yml for cloud deployment - Comprehensive README documentation
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""
|
|
Sentiment Tagger Plugin
|
|
Adds sentiment scores and labels to posts and comments.
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add parent to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from plugins import Plugin
|
|
from analytics.sentiment import analyze_sentiment
|
|
|
|
|
|
class SentimentTagger(Plugin):
|
|
"""Add sentiment analysis to scraped content."""
|
|
|
|
name = "sentiment_tagger"
|
|
description = "Adds sentiment scores and labels to posts"
|
|
enabled = True
|
|
|
|
def process_posts(self, posts):
|
|
"""Add sentiment to posts."""
|
|
for post in posts:
|
|
text = f"{post.get('title', '')} {post.get('selftext', '')}"
|
|
score, label = analyze_sentiment(text)
|
|
post['sentiment_score'] = score
|
|
post['sentiment_label'] = label
|
|
|
|
# Count sentiments
|
|
pos = sum(1 for p in posts if p.get('sentiment_label') == 'positive')
|
|
neg = sum(1 for p in posts if p.get('sentiment_label') == 'negative')
|
|
neu = len(posts) - pos - neg
|
|
|
|
print(f" 📊 Sentiment: {pos} positive, {neu} neutral, {neg} negative")
|
|
return posts
|
|
|
|
def process_comments(self, comments):
|
|
"""Add sentiment to comments."""
|
|
for comment in comments:
|
|
score, label = analyze_sentiment(comment.get('body', ''))
|
|
comment['sentiment_score'] = score
|
|
comment['sentiment_label'] = label
|
|
|
|
return comments
|