🎯 AI价格监视器
由人工智能代理支持的自动化电子商务价格跟踪和警报系统
    
📖 概述
AI价格监视器 是一个智能的分布式价格监控系统,旨在跨多个平台跟踪电子商务产品价格。作为ENSA Agadir分布式系统课程项目的一部分,它利用尖端的人工智能技术通过Telegram提供智能价格分析、自动警报和对话交互。
✨ 主要特点
- 🤖 人工智能驱动的多智能体系统 -使用Claude AI进行LangGraph编排
- 📊 智能价格分析 -自动检测购买机会和趋势
- 💬 Telegram聊天机器人界面 -用于监控和查询的自然语言交互
- 🔄 N8N工作流自动化 -与工作流自动化无缝集成
- 📧 多通道警报 -电子邮件、电报和JSON格式的报告
- 🗄️ 完整的价格历史记录 -具有完整跟踪和统计功能的SQLite数据库
- 🌐 RESTful API -基于FastAPI的后端,具有全面的端点
- 🎨 美丽的报告 -HTML和JSON格式的报告,带有AI生成的摘要
🏗️ 建筑
┌─────────────────┐
│ Telegram Bot │ ← User interaction
└────────┬────────┘
│
┌────▼─────┐
│ N8N │ ← Workflow orchestration
│ Workflow │
└────┬─────┘
│
┌────▼─────────────┐
│ FastAPI Server │ ← REST API
└────┬─────────────┘
│
┌────▼──────────────────────┐
│ LangGraph AI Agents │
├───────────────────────────┤
│ • Price Monitor Agent │ ← Web scraping & extraction
│ • Analysis Agent │ ← Trend detection & insights
│ • Notification Agent │ ← Report generation
└────┬──────────────────────┘
│
┌────▼─────┐
│ SQLite │ ← Data persistence
└──────────┘🤖 多代理系统
- 价格监控代理
- 使用BeautifulSoup进行智能网页抓取 - 使用Claude进行人工智能辅助价格提取 - 复杂的CSS选择器处理 - 多站点支持(亚马逊、苹果等)
- 分析代理
- 随时间变化的价格趋势分析 - 购买机会检测 - 统计计算(最小/最大/平均) - 与Claude一起生成AI摘要
- 通知代理
- 优雅的HTML报告生成 - N8N工作流的JSON导出 - 多渠道通知(电子邮件、电报) - 自动报告归档
🚀 快速开始
先决条件
- Python 3.12+
- 人类克劳德API密钥
- 电报机器人令牌(来自@BotFather)
- N8N云帐户(可选)
- ngrok(促进地方发展)
安装
# Clone the repository
git clone https://github.com/yourusername/ai-price-monitor.git
cd ai-price-monitor
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your API keys配置
编辑 .env 文件:
# Anthropic API Key (required)
ANTHROPIC_API_KEY=sk-ant-api03-xxxxx
# Database
DATABASE_PATH=price_monitor.db
# Monitoring Configuration
CHECK_INTERVAL_HOURS=1
PRICE_CHANGE_THRESHOLD=5.0 # Alert threshold %
# Notifications
EMAIL_RECIPIENT=your-email@example.com
ADMIN_TELEGRAM=your_telegram_chat_id运行应用程序
# Start FastAPI server
python main.py
# Server runs on http://localhost:8000
# API docs: http://localhost:8000/docs使用ngrok公开API(适用于N8N云)
# In a new terminal
ngrok http 8000
# Copy the ngrok URL (e.g., https://abc123.ngrok.io)
# Use this URL in N8N as API_BASE_URL📡 API终点
| 端点 | 方法 | 描述 |
|---|---|---|
/ | 获取 | API主页 |
/docs | GET | Swagger文档 |
/health | GET | 健康检查 |
/products | GET | 列出所有受监控的产品 |
/add-product | POST | 添加新产品 |
/monitor | POST | 运行价格监控 |
/stats/{product_name} | GET | 获取产品统计信息 |
/history/{product_name} | GET | 获取价格历史记录 |
/report | GET | 最新HTML报告 |
/report/json | GET | 最新JSON报告 |
/test-scraping | POST | 测试刮擦配置 |
API使用示例
# List all products
curl http://localhost:8000/products
# Add a product
curl -X POST http://localhost:8000/add-product \
-H "Content-Type: application/json" \
-d '{
"name": "Samsung Galaxy A35 5G",
"url": "https://www.amazon.fr/dp/B0CV4HLFPX",
"selector": ".a-price-whole"
}'
# Test scraping configuration
curl -X POST http://localhost:8000/test-scraping \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.amazon.fr/dp/B0CV4HLFPX",
"selector": ".a-price-whole"
}'
# Run monitoring
curl -X POST http://localhost:8000/monitor
# Get product statistics
curl http://localhost:8000/stats/Samsung%20Galaxy%20A35%205G
# View HTML report
open http://localhost:8000/report🔄 N8N工作流集成
设置N8N工作流
- 创建电报机器人
- 打开Telegram并搜索 @BotFather - 发送 /newbot 并遵循指示 - 保存您的Bot令牌
- 导入工作流
- 打开N8N云 - 点击“从文件导入” - 选择 n8n_workflow_price_monitor.json
- 配置凭据
- 电报机器人API:添加您的机器人令牌 - API人类克劳德:添加API密钥 - SMTP帐户:配置电子邮件设置
- 设置环境变量
- API_BASE_URL:您的ngrok URL - ADMIN_EMAIL:您的电子邮件地址 - ADMIN_TELEGRAM:您的Telegram聊天ID
- 激活工作流
- 点击右上角的切换开关 - 工作流现在将监听Telegram消息
电报机器人命令
用户可以使用自然语言与机器人进行交互:
User: "show all products"
Bot: 📊 Here are all monitored products:
1. Samsung Galaxy A35 5G - €229.00
2. GRIFEMA Spray Bottle - €8.99
User: "monitor Samsung Galaxy"
Bot: 🔍 Monitoring Complete!
✅ Scraped: 1 products
💰 Opportunities: 1
[Sends detailed report]
User: "price history of Samsung"
Bot: 📜 Price History: Samsung Galaxy A35 5G
• €229.00 - Jan 14, 03:00 PM
• €250.00 - Jan 14, 01:00 PM
📉 Trend: -8.4%
User: "stats for Samsung Galaxy A35 5G"
Bot: 📈 Statistics for Samsung Galaxy A35 5G
💰 Current: €229.00
📉 Min: €229.00
📊 Avg: €239.50
📈 Max: €250.00📊 项目结构
price-monitor/
├── main.py # FastAPI application
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── n8n_workflow_price_monitor.json # N8N workflow
├── insert_test_price.py # Test data helper
├── agents/
│ ├── __init__.py
│ ├── price_monitor.py # Web scraping & price extraction
│ ├── analysis.py # Trend analysis & opportunity detection
│ └── notification.py # Report generation & alerts
│
├── database/
│ ├── __init__.py
│ └── models.py # SQLite database models
│
├── mcp/ # Model Context Protocol (optional)
│ ├── __init__.py
│ └── clients.py
│
└── reports/ # Generated reports
├── latest_report.html
├── latest_report.json
└── report_*.html🗄️ 数据库模式
表格
产品
CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
url TEXT NOT NULL UNIQUE,
selector TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);价格历史
CREATE TABLE price_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
product_id INTEGER NOT NULL,
price REAL NOT NULL,
currency TEXT DEFAULT 'EUR',
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
metadata TEXT,
FOREIGN KEY (product_id) REFERENCES products (id)
);警报
CREATE TABLE alerts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
product_id INTEGER NOT NULL,
old_price REAL NOT NULL,
new_price REAL NOT NULL,
change_percent REAL NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
notified BOOLEAN DEFAULT 0,
FOREIGN KEY (product_id) REFERENCES products (id)
);数据库管理
# Access database
sqlite3 price_monitor.db
# View all products
SELECT * FROM products;
# View recent price history
SELECT p.name, ph.price, ph.timestamp
FROM products p
LEFT JOIN price_history ph ON p.id = ph.product_id
ORDER BY ph.timestamp DESC
LIMIT 10;
# Insert test price
INSERT INTO price_history (product_id, price, timestamp)
VALUES (1, 199.99, datetime('now'));🛠️ 技术栈
- 后端框架:FastAPI
- AI/ML:《语言图谱》、《语言链》、克劳德·十四行诗4.5
- 工作流程自动化:N8N云
- 数据库:SQLite
- 网络爬取:BeautifulSoup4,请求
- 消息传递:Telegram Bot API
- 数据验证:Pydantic
- 隧道效应:ngrok(发展)
🎓 学术背景
该项目是作为 分布式系统(Distributed Systems) 课程在 ENSA Agadir(国家应用科学学院-阿加迪尔),演示:
- ✅ 分布式多智能体系统架构
- ✅ 工作流编排和自动化
- ✅ 分布式环境中的AI集成
- ✅ RESTful API的设计与实现
- ✅ 多通道通信模式
- ✅ 数据库持久性和数据管理
- ✅ 实时数据处理和分析
团队成员
- Achraf EL BANOURI -开发与架构
- Mehdi BEN JBALI -开发与测试
- 优素福·奥布里克 -开发和文件
机构
国家应用科学学院-阿加迪尔\ 计算机工程-第三年\ 课程:分布式系统(Distributed Systems)
🧪 测试
手动测试
# Start the server
python main.py
# In another terminal, run tests
curl -X POST http://localhost:8000/monitor
# Check the report
curl http://localhost:8000/report
# Verify database
python insert_test_price.py测试工作流程
- 添加产品 通过API或直接在数据库中
- 插入测试价格 模拟价格变化
- 运行监控 检测变化
- 验证报告 正确生成
- 测试电报机器人 使用自然语言查询
🐛 故障排除
报废错误
问题: Scraping failed for product X
解决方案:
- 使用浏览器DevTools验证CSS选择器
- 测试用
/test-scraping端点 - 检查网站是否阻止机器人程序(调整标题)
未检测到价格变化
问题:尽管价格发生变化,但没有警报
解决方案:
- 检查
PRICE_CHANGE_THRESHOLD在.env - 验证数据库中的价格历史记录
- 默认阈值为5%
电报机器人没有响应
问题:Bot不响应消息
解决方案:
- 确保工作流程 已激活 (打开)
- 检查N8N webhook是否已注册
- 验证Telegram机器人令牌是否正确
- 检查ngrok是否正在运行,URL是否已更新
API连接错误
问题:N8N无法访问localhost API
解决方案:
- 使用ngrok公开localhost
- 更新
API_BASE_URL在N8N环境中 - 确保FastAPI服务器正在运行
📈 未来的增强功能
- \[\]支持更多电子商务平台
- \[\]机器学习价格预测
- \[\]React web仪表板
- \[\]WhatsApp通知
- \[\]多站点价格比较
- \[\]个性化推荐API
- \[\]CSV/Excel数据导出
- \[\]带有图表的分析仪表板
- \[\]按产品定制价格警报
- \[\]移动应用程序
🤝 贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
📧 联系
如有疑问或建议,请联系:
Achraf EL BANOURI
- 电子邮件:achrafbnr2406@gmail.com
- github: @AchrafELBANOURI
🙏 致谢
- Anthropic 对于Claude AI API
- N8N 工作流自动化平台
- 语言链/语言图 用于代理编排
- ENSA 阿加迪尔 学术支持和资源
______________________________________________________________________
⭐ 如果你觉得这个项目有用,请给它一颗星!
由...制作❤️ 使用LangGraph、Claude AI和N8N
