Conduct market research, user feedback collection, technical solution research, and other tasks based on the Reddit API (PRAW).
Environment Configuration
The following environment variables need to be set (in the .env file):
REDDIT_CLIENT_ID=your_client_id
REDDIT_CLIENT_SECRET=your_client_secret
REDDIT_USER_AGENT=your_app_name/1.0
OPENROUTER_API_KEY=your_openrouter_key # 用于 AI 分析
Core Scripts
1. search_reddit.py - Reddit Search
Search content across all of Reddit or within a specific subreddit.
python scripts/search_reddit.py --query "关键词" [选项]
Parameters:
--query: Search keyword (required)--subreddit: Limit the search to a subreddit (optional; if not specified, search all of Reddit)--limit: Number of results to return (default 25, maximum 100)--time_filter: Time range [all, year, month, week, day, hour] (default all)--sort: Sorting method [relevance, hot, top, new, comments] (default relevance)--output: Output file path (optional; by default output to stdout)
Example:
# 搜索 AI 相关讨论
python scripts/search_reddit.py --query "AI productivity tools" --limit 50 --time_filter month
# 在特定 subreddit 搜索
python scripts/search_reddit.py --query "团建" --subreddit "China_irl" --limit 30
2. fetch_posts.py - Fetch Subreddit Posts
Fetch hot/latest posts and comments from a specified subreddit.
python scripts/fetch_posts.py --subreddit "subreddit名称" [选项]
Parameters:
--subreddit: Target subreddit (required)--sort: Sorting method [hot, new, top, rising, controversial] (default hot)--limit: Number of posts (default 25)--time_filter: Time range, only valid for top/controversial (default week)--include_comments: Whether to include comments (default false)--comment_limit: Number of comments per post (default 10)--output: Output file path
Example:
# 获取 startup subreddit 热门帖子
python scripts/fetch_posts.py --subreddit "startups" --sort hot --limit 20
# 获取帖子及评论
python scripts/fetch_posts.py --subreddit "smallbusiness" --include_comments --comment_limit 20
3. analyze_reddit.py - In-Depth Analysis
Perform AI analysis on collected Reddit data and generate a research report.
python scripts/analyze_reddit.py --input "数据文件" --analysis_type "分析类型" [选项]
Parameters:
--input: Input data file (JSON format, from search or fetch)--analysis_type: Analysis type [sentiment, topic, summary, competitive, pain_points]--model: AI model (default gemini; options include claude, gpt-4)--output: Output report path--format: Output format [json, markdown] (default markdown)
Analysis Type Descriptions:
sentiment: Sentiment analysis, identifying positive/negative/neutral opinionstopic: Topic clustering, identifying discussion hotspotssummary: Content summarization, extracting key informationcompetitive: Competitive analysis, identifying mentioned competitors and evaluationspain_points: Pain point analysis, identifying user complaints and needs
Example:
# 情感分析
python scripts/analyze_reddit.py --input data/search_results.json --analysis_type sentiment
# 生成 Markdown 报告
python scripts/analyze_reddit.py --input data/posts.json --analysis_type pain_points --format markdown --output reports/pain_points.md
Research Workflow
Typical Research Process
-
Define research objectives
- Clarify the questions to be studied
- Determine the list of target subreddits
- Set the time range and sample size
-
Data collection
# 1. 搜索相关讨论 python scripts/search_reddit.py --query "your topic" --limit 100 --output data/search.json # 2. 获取热门帖子 python scripts/fetch_posts.py --subreddit "relevant_sub" --include_comments --output data/posts.json -
Data analysis
# 3. 运行 AI 分析 python scripts/analyze_reddit.py --input data/search.json --analysis_type pain_points --output reports/analysis.md -
Report generation
- Integrate multiple analysis results
- Add conclusions and recommendations
- Output the final report
Common Research Scenarios
Scenario 1: Market Research
# 了解目标用户对某类产品的看法
python scripts/search_reddit.py --query "team building software" --limit 100 --time_filter year
python scripts/analyze_reddit.py --input results.json --analysis_type competitive
Scenario 2: User Feedback Collection
# 收集特定产品的用户反馈
python scripts/search_reddit.py --query "Notion alternative" --subreddit "productivity" --limit 50
python scripts/analyze_reddit.py --input results.json --analysis_type pain_points
Scenario 3: Technical Solution Research
# 了解技术选型讨论
python scripts/fetch_posts.py --subreddit "programming" --sort top --time_filter month --include_comments
python scripts/analyze_reddit.py --input posts.json --analysis_type topic
Output Formats
JSON format (structured data)
{
"query": "搜索词",
"timestamp": "2024-01-15T10:30:00Z",
"total_results": 50,
"results": [
{
"id": "post_id",
"title": "帖子标题",
"author": "用户名",
"subreddit": "subreddit名",
"score": 1234,
"num_comments": 56,
"created_utc": 1705312200,
"url": "https://reddit.com/...",
"selftext": "帖子内容...",
"comments": [...]
}
]
}
Markdown format (readable report)
# Reddit 调研报告:[主题]
## 概述
- 数据来源:[subreddit 列表]
- 时间范围:[开始] - [结束]
- 样本量:[N] 条帖子
## 关键发现
1. ...
2. ...
## 详细分析
### 主题分布
...
### 情感倾向
...
## 结论与建议
...
Notes
- API limits: The Reddit API has rate limits (approximately 60 requests/minute), so large-scale data collection must be done in batches
- Data Privacy: Do not collect or store users' personal information
- Content Copyright: Cite the source when quoting Reddit content
- Compliant Use: Comply with the Reddit API Terms of Use
Dependency Installation
cd .claude/skills/research-by-reddit/scripts
pip install -r requirements.txt
Troubleshooting
FAQ
-
Authentication failed
- Check whether REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET are correct
- Ensure the Reddit application type is "script"
-
Search results are empty
- Try broadening the time range
- Check the keyword spelling
- Try a different subreddit
-
AI analysis failed
- Check whether OPENROUTER_API_KEY is valid
- Ensure the input file format is correct