wechat_msg_crawler/COLLECT_README.md

94 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 微信群聊消息采集器
自动扫描所有微信群聊,增量采集新消息,存入 MySQL媒体文件上传腾讯 COS。
## 前置条件
0. 安装 wechat-cli
cd wechat-cli
pip install -e .
微信版本建议 4.1.6 或 4.1.8
1. **微信已登录**`wechat-cli` 已初始化:
```bash
sudo wechat-cli init
```
2. **安装依赖**
```bash
pip3 install pymysql cos-python-sdk-v5
```
## 快速启动
```bash
cd /Users/makee/Documents/cris/workspace/wechat-cli
# 查看所有群聊
python3 collect_chats.py groups
# 一次性扫描(测试用)
python3 collect_chats.py scan
# 守护模式(持续运行)
python3 collect_chats.py daemon
# 查看采集统计
python3 collect_chats.py status
# 停止采集某个群
python3 collect_chats.py disable "广告群"
# 恢复采集
python3 collect_chats.py enable "广告群"
```
## 扫描策略
采集器使用自适应频率扫描:
| 活跃度 | 条件 | 扫描间隔 |
|--------|------|----------|
| HOT | 最新消息 < 5 分钟 | 60 |
| WARM | 最新消息 < 1 小时 | 5 分钟 |
| COLD | 无近期消息 | 逐步退避至 30 分钟 |
- 每轮最多扫描 5 个群群间随机延迟 0~3
- 5 分钟重新发现新群聊
- 支持白名单/黑名单过滤正则匹配
## 自定义配置
创建 `~/.wechat-cli/collect-chats/config.json`可选所有字段都有默认值
```json
{
"min_interval": 60,
"base_interval": 300,
"max_interval": 1800,
"batch_size": 5,
"messages_per_scan": 200,
"whitelist": [],
"blacklist": ["广告群", ".*测试.*"]
}
```
## 数据存储
- **消息** MySQL `vala_test.wechat_group_message`
- **媒体文件**语音/视频/文件)→ 腾讯 COS `vala_llm/user_feedback/wechat/类型/YYYY-MM/`
- **图片** 暂不采集微信 V2 AES 加密限制
## 后台运行
```bash
# nohup 方式
nohup python3 collect_chats.py daemon > collector.log 2>&1 &
# 查看日志
tail -f collector.log
# 停止
kill $(pgrep -f "collect_chats.py daemon")
```