| name | llm-intelligent-public-opinion-analytics |
| description | Deploy and use an LLM-powered public opinion analytics assistant that crawls 26 hot lists from 15 platforms, performs sentiment analysis, topic clustering, and multi-channel alerting |
| triggers | ["set up public opinion monitoring system","analyze social media trending topics","deploy sentiment analysis crawler","configure hot topic push notifications","cluster trending news topics","monitor multiple platform hot searches","build opinion analytics dashboard","aggregate cross-platform trending content"] |
LLM-Based Intelligent Public Opinion Analytics Assistant
Skill by ara.so — Data Skills collection.
Overview
This project is a comprehensive public opinion analytics platform that combines real-time data from 26 hot lists across 15 mainstream platforms (Weibo, Bilibili, Zhihu, Baidu, etc.) with large language model (LLM) analysis capabilities. It provides conversational query interfaces for hot searches, topic clustering, sentiment analysis, and multi-channel push notifications (WeChat, Email, Telegram).
Key Capabilities:
- Real-time crawler cluster for 15+ platforms
- LLM-powered content analysis (including video content extraction)
- Natural language query interface
- Topic clustering and sentiment analysis
- Multi-channel alert system (Email, WeChat Work, Telegram)
- Keyboard shortcuts for crawler control
Installation
Prerequisites
- Browser Driver Setup (Required for detail page scraping):
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
chromedriver --version
- MySQL Database:
mysql -u root -p
CREATE DATABASE hotsearch_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'hotsearch_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON hotsearch_db.* TO 'hotsearch_user'@'localhost';
FLUSH PRIVILEGES;
- Python Environment:
git clone https://github.com/hmmnxkl/LLM-Based-Intelligent-Public-Opinion-Analytics-Assistant.git
cd LLM-Based-Intelligent-Public-Opinion-Analytics-Assistant
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Database Initialization
Reference the init.py file to create necessary tables:
import pymysql
connection = pymysql.connect(
host='localhost',
user='hotsearch_user',
password='your_password',
database='hotsearch_db',
charset='utf8mb4'
)
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS hot_search_items (
id INT AUTO_INCREMENT PRIMARY KEY,
platform VARCHAR(50) NOT NULL,
rank INT,
title VARCHAR(500) NOT NULL,
url VARCHAR(1000),
heat_value VARCHAR(100),
crawl_time DATETIME NOT NULL,
detail_content TEXT,
sentiment VARCHAR(20),
INDEX idx_platform (platform),
INDEX idx_crawl_time (crawl_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
""")
connection.commit()
connection.close()
Configuration
Environment Variables
Create .env file in the project root:
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=hotsearch_user
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=hotsearch_db
OPENAI_API_KEY=your_api_key
OPENAI_API_BASE=https://your-llm-endpoint.com/v1
OPENAI_MODEL=gpt-4
PANGU_API_KEY=your_pangu_key
PANGU_API_BASE=https://pangu-api.huaweicloud.com
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password
WECHAT_WORK_WEBHOOK=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY
WECHAT_WORK_CORP_ID=your_corp_id
WECHAT_WORK_APP_SECRET=your_app_secret
WECHAT_WORK_AGENT_ID=your_agent_id
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
Crawler Settings
Edit hotsearchcrawler/settings.py:
MYSQL_CONFIG = {
'host': os.getenv('MYSQL_HOST', 'localhost'),
'port': int(os.getenv('MYSQL_PORT', 3306)),
'user': os.getenv('MYSQL_USER'),
'password': os.getenv('MYSQL_PASSWORD'),
'database': os.getenv('MYSQL_DATABASE'),
'charset': 'utf8mb4',
'autocommit': True
}
PLATFORM_COOKIES = {
'weibo': 'your_weibo_cookies',
'bilibili': 'your_bilibili_cookies'
}
CONCURRENT_REQUESTS = 16
DOWNLOAD_DELAY = 1
USER_AGENTS = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
]
Usage
Starting the System
source venv/bin/activate
python app.py
Crawler Management
cd hotsearchcrawler
python runspider-test.py
python run_spiders.py
Via Web Interface:
- Use keyboard shortcuts to start/stop crawlers
- View real-time crawling status
- Monitor data collection metrics
Natural Language Queries
Programmatic API Usage
from hotsearch_analysis_agent.analyzer import OpinionAnalyzer
from datetime import datetime, timedelta
analyzer = OpinionAnalyzer()
results = analyzer.query_hot_searches(
platforms=['weibo', 'zhihu', 'bilibili'],
time_range=(datetime.now() - timedelta(hours=24), datetime.now()),
keyword='人工智能'
)
sentiment = analyzer.analyze_sentiment(results)
print(f"Overall sentiment: {sentiment['overall']}")
print(f"Positive: {sentiment['positive_ratio']}%")
clusters = analyzer.cluster_topics(results, num_clusters=5)
for i, cluster in enumerate(clusters):
print(f"Cluster {i+1}: {cluster['keywords']}")
print(f" Items: {len(cluster['items'])}")
Push Notification Setup
from hotsearch_analysis_agent.push_service import PushService
push_service = PushService()
task = push_service.create_task(
name="AI Technology Daily Report",
keywords=['人工智能', '大模型', '机器学习'],
platforms=['weibo', 'zhihu', 'bilibili'],
schedule='0 8,12,18 * * *',
channels=['wechat_work', 'email'],
threshold={'heat_value': 100000, 'sentiment': 'positive'}
)
python test_push_task.py
Analysis Report Generation
from hotsearch_analysis_agent.report_generator import ReportGenerator
generator = ReportGenerator()
report = generator.generate_report(
topic="人工智能与前沿科技",
time_range=(datetime.now() - timedelta(days=7), datetime.now()),
include_sentiment=True,
include_clustering=True,
include_trend_analysis=True
)
report.save_markdown('output/ai_tech_report.md')
report.save_pdf('output/ai_tech_report.pdf')
Common Patterns
Multi-Platform Data Aggregation
from hotsearch_analysis_agent.aggregator import DataAggregator
aggregator = DataAggregator()
merged_data = aggregator.aggregate(
platforms=['weibo', 'douyin', 'zhihu', 'bilibili', 'baidu'],
dedup_threshold=0.8,
sort_by='heat_value',
limit=50
)
correlations = aggregator.find_correlations(merged_data)
print(f"Found {len(correlations)} cross-platform trending topics")
Video Content Analysis
from hotsearch_analysis_agent.video_analyzer import VideoAnalyzer
video_analyzer = VideoAnalyzer()
video_topics = video_analyzer.extract_content(
url='https://www.bilibili.com/video/BV13pSoBBEvX/',
extract_comments=True,
max_comments=100
)
print(f"Video title: {video_topics['title']}")
print(f"Description: {video_topics['description']}")
print(f"Top comments sentiment: {video_topics['comments_sentiment']}")
Custom LLM Integration
from hotsearch_analysis_agent.llm_client import LLMClient
llm = LLMClient(
api_base=os.getenv('PANGU_API_BASE'),
api_key=os.getenv('PANGU_API_KEY'),
model='pangu-embedded-7b'
)
llm = LLMClient(
api_base=os.getenv('OPENAI_API_BASE'),
api_key=os.getenv('OPENAI_API_KEY'),
model='gpt-4'
)
analysis = llm.analyze(
content=news_content,
task='sentiment_and_summary',
language='zh'
)
Scheduled Monitoring
from hotsearch_analysis_agent.scheduler import MonitorScheduler
scheduler = MonitorScheduler()
scheduler.add_rule(
name="Tech Company Crisis Monitoring",
keywords=['某公司', '丑闻', '争议'],
alert_conditions={
'heat_spike': 2.0,
'sentiment_drop': -0.3,
'platforms_count': 3
},
notification_channels=['wechat_work', 'telegram', 'email'],
urgent=True
)
scheduler.start()
Troubleshooting
Browser Driver Issues
which chromedriver
google-chrome --version
CHROMEDRIVER_PATH=/path/to/chromedriver
Database Connection Errors
sudo systemctl status mysql
mysql -u hotsearch_user -p -h localhost hotsearch_db
file -I .env
import pymysql
try:
conn = pymysql.connect(
host=os.getenv('MYSQL_HOST'),
user=os.getenv('MYSQL_USER'),
password=os.getenv('MYSQL_PASSWORD'),
database=os.getenv('MYSQL_DATABASE')
)
print("Connection successful")
except Exception as e:
print(f"Error: {e}")
Crawler Rate Limiting
CONCURRENT_REQUESTS = 8
DOWNLOAD_DELAY = 2
AUTOTHROTTLE_ENABLED = True
AUTOTHROTTLE_START_DELAY = 1
AUTOTHROTTLE_MAX_DELAY = 10
DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
'scrapy_user_agents.middlewares.RandomUserAgentMiddleware': 400,
}
LLM API Timeouts
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=1, max=10))
def call_llm_with_retry(prompt):
return llm.analyze(prompt)
from hotsearch_analysis_agent.batch_processor import BatchProcessor
processor = BatchProcessor(batch_size=10, delay=2)
results = processor.process_items(news_items, analyze_func)
Memory Issues with Large Datasets
from hotsearch_analysis_agent.db_client import DBClient
db = DBClient()
for batch in db.stream_hot_searches(batch_size=100):
process_batch(batch)
aggregated = db.aggregate_by_platform(
start_date='2026-01-01',
end_date='2026-05-01'
)
Project Structure Reference
.
├── app.py # Main application entry
├── hotsearch_analysis_agent/ # Analysis system
│ ├── analyzer.py # Core analysis logic
│ ├── llm_client.py # LLM integration
│ ├── report_generator.py # Report generation
│ ├── push_service.py # Notification service
│ └── scheduler.py # Task scheduling
├── hotsearchcrawler/ # Crawler cluster
│ ├── spiders/ # Platform-specific spiders
│ ├── settings.py # Crawler settings
│ └── run_spiders.py # Crawler launcher
├── test_push_task.py # Push notification testing
├── runspider-test.py # Single crawler testing
├── init.py # Database initialization
├── requirements.txt # Python dependencies
└── .env # Environment configuration
Best Practices
- Database Indexing: Ensure indexes on
platform, crawl_time, and title columns for fast queries
- LLM Cost Management: Cache analysis results to avoid redundant API calls
- Crawler Politeness: Respect platform rate limits and robots.txt
- Notification Throttling: Implement cooldown periods to avoid alert fatigue
- Data Retention: Set up automatic archival for data older than 90 days
- Model Choice: Consider Huawei Pangu for better Chinese language understanding and local deployment