Skip to content

lecrix/buff-price-alert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔔 Buff Price Alert

自动监控 buff.163.com CS2 饰品价格,发现低价立即微信通知

Python License Platform


✨ 功能特性

  • 🎯 灵活配置 — 支持同时监控多款饰品,每款可设置多个磨损值区间
  • 📊 智能比价 — 对比同区间最低价与第二低价,差价超过阈值才触发通知
  • 📱 微信推送 — 通过 Server酱 实时推送到微信,低价不错过
  • 时段控制 — 自定义监控时段,非监控时段自动休眠
  • 🔄 智能防封 — 多饰品自动轮转,请求间隔加入随机抖动(Jitter)模拟真人,降低限流风险
  • 📝 日志记录 — 运行日志自动保存,支持终端实时查看与文件回溯
  • 🛡️ 容错处理 — 网络异常、Cookie 过期、接口限流等均有完善的错误处理

📋 目录


🚀 快速开始

环境要求

  • Python 3.10 或更高版本
  • pip 包管理器

1. 克隆项目

git clone https://github.com/lecris/buff-price-alert.git
cd buff-price-alert

2. 安装依赖

pip install -r requirements.txt

3. 配置

cp config.example.yaml config.yaml   # Linux / macOS
copy config.example.yaml config.yaml  # Windows

编辑 config.yaml,填入以下信息:

配置项 来源
buff_cookie 获取 Buff Cookie →
serverchan_key 获取 Server酱 SendKey →
items 配置监控饰品 →

4. 测试

运行前建议逐步测试各模块:

python analyzer.py    # 测试价格分析逻辑(离线,无需网络)
python notifier.py    # 测试微信推送(需要 SendKey)
python buff_api.py    # 测试 Buff API 连通性(需要 Cookie)

5. 启动监控

python main.py

Ctrl + C 停止。


⚙️ 配置说明

基本参数

schedule:
  start_hour: 9       # 监控开始时间(24小时制)
  end_hour: 24        # 监控结束时间(24 = 午夜 0 点)

request_interval: 7             # 每条查询之间的间隔(秒)
price_threshold_percent: 2      # 价格差异阈值(%),低于第二低价此百分比触发通知
notify_cooldown_minutes: 15     # 同一饰品通知冷却时间(分钟)

💡 防封机制:程序会自动在 request_interval 的基础上增加 ±30% 的随机抖动(Jitter)。例如设置 15 秒,实际请求间隔会在 10.5 ~ 19.5 秒之间随机摆动,有效避免触发固定频率的机器检测。建议设置在 15-30 秒之间。

监控饰品配置

支持同一饰品配置多个磨损值区间,实现全面覆盖:

items:
  # 饰品 A — 区间 1
  - name: "AWP | 克拉考 (久经沙场 0.15-0.18)"
    goods_id: 968298
    min_paintwear: 0.15
    max_paintwear: 0.18

  # 饰品 A — 区间 2
  - name: "AWP | 克拉考 (久经沙场 0.18-0.21)"
    goods_id: 968298
    min_paintwear: 0.18
    max_paintwear: 0.21

  # 饰品 B
  - name: "AK-47 | 火蛇 (久经沙场 0.15-0.18)"
    goods_id: 34474
    min_paintwear: 0.15
    max_paintwear: 0.18
如何找到 goods_id?

打开 Buff 上某款饰品的页面,URL 中的数字即为 goods_id

https://buff.163.com/goods/968298
                              ↑
                         goods_id

💡 建议:在 name 中标注磨损区间(如 0.15-0.18),方便收到微信推送时快速定位。

完整参数一览

参数 类型 默认值 说明
buff_cookie string Buff 登录 Cookie
serverchan_key string Server酱 SendKey
schedule.start_hour int 9 监控开始时间
schedule.end_hour int 24 监控结束时间
request_interval int 7 查询间隔(秒)
price_threshold_percent float 2 价格差异阈值(%)
notify_cooldown_minutes int 15 通知冷却时间(分钟)

📖 使用指南

获取 Buff Cookie

  1. 使用 Chrome 打开 buff.163.com登录
  2. F12 打开开发者工具
  3. 切换到 Network(网络)标签页
  4. 在 Buff 页面上随意点击一个饰品
  5. 在 Network 列表中点击任意一条对 buff.163.com 的请求
  6. 在右侧 Headers 面板中找到 Cookie: 字段
  7. 右键 → 复制值,粘贴到 config.yaml

⚠️ Cookie 会定期过期(通常几天到几周),届时需重新获取。建议使用小号

获取 Server酱 SendKey

  1. 访问 sct.ftqq.com
  2. 微信扫码登录
  3. 复制页面上显示的 SendKey
  4. 关注「方糖」服务号以接收推送

💡 免费版每天可推送 5 条消息,对于低价提醒通常足够。

后台运行

Windows:

# 使用 pythonw(无窗口后台运行)
pythonw main.py

# 或使用 PowerShell 开启独立窗口
Start-Process powershell -ArgumentList "-NoExit", "-Command", "python main.py"

Linux / macOS:

nohup python main.py &

🔍 工作原理

┌─────────────────────────────────────────────────────────────┐
│                       主循环 (main.py)                       │
│                                                             │
│   ┌──────────┐    ┌──────────┐    ┌──────────┐             │
│   │ 时段检查  │───→│ 饰品轮转  │───→│ 随机间隔  │──→ 循环     │
│   └──────────┘    └────┬─────┘    └──────────┘             │
│                        │                                    │
│                        ▼                                    │
│               ┌────────────────┐                            │
│               │   Buff API     │  buff_api.py               │
│               │  查询在售列表   │                            │
│               └───────┬────────┘                            │
│                       │                                     │
│                       ▼                                     │
│               ┌────────────────┐                            │
│               │   价格分析      │  analyzer.py               │
│               │ 最低价 vs 第二低│                            │
│               └───────┬────────┘                            │
│                       │ 差价 ≥ 阈值?                        │
│                       ▼                                     │
│               ┌────────────────┐                            │
│               │   微信推送      │  notifier.py               │
│               │  Server酱通知   │                            │
│               └────────────────┘                            │
└─────────────────────────────────────────────────────────────┘

比价逻辑:脚本查询指定磨损区间内的所有在售饰品,按价格排序后取最低价与第二低价。当最低价比第二低价便宜超过阈值百分比时,判定为低价,触发微信通知。


❓ 常见问题

Cookie 过期了怎么办?

重新登录 Buff,按照上述步骤重新获取 Cookie,更新 config.yaml 后重启脚本。

微信收不到推送?
  1. 确认已关注「方糖」服务号
  2. 运行 python notifier.py 发送测试消息
  3. 检查 config.yaml 中的 serverchan_key 是否正确
  4. 检查 Server酱免费版每日推送额度(5 条)是否用完
被 Buff 限流了?

增大 config.yaml 中的 request_interval(如改为 15-30 秒),或减少监控条目数量。

如何添加更多饰品?

config.yamlitems 列表中追加条目即可,格式参考已有条目。重启脚本生效。

日志在哪里?
  • 实时查看:运行脚本的终端窗口
  • 历史记录logs/monitor_YYYYMMDD.log(按日期自动归档)

⚠️ 免责声明

  • 本项目仅供学习交流使用,请勿用于商业用途
  • Buff API 为非官方接口,使用时请遵守 buff.163.com 的服务条款
  • 过于频繁的请求可能导致账号被临时限制,请合理设置查询间隔
  • 作者不对因使用本工具产生的任何损失负责

📄 License

本项目基于 MIT License 开源。

About

自动监控 buff.163.com CS2 饰品价格,发现低价立即微信通知

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages