# BiddingAgent **Repository Path**: automatic_aiming/bidding-agent ## Basic Information - **Project Name**: BiddingAgent - **Description**: 投标机器人 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-08 - **Last Updated**: 2026-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # BiddingAgent BiddingAgent 定时抓取鞍钢招投标信息,通过 DeepSeek 判断项目是否值得投标,使用企业微信机器人推送推荐结果,并用 SQLite 保存项目和分析历史。 ## 主要功能 - 按配置条件抓取最新招标项目。 - 根据团队资质、业绩方向和风险规则调用 DeepSeek 分析。 - 区分新增推荐、重复推荐和结论冲突项目。 - 每天定时执行,也支持 HTTP 接口立即触发。 - 使用 SQLite 去重并保存分析历史。 - 保存滚动日志和每轮 TXT 分析报告。 主流程: ```text 抓取项目 -> 数据库去重 -> DeepSeek 分析 -> 企业微信通知 -> 保存状态 ``` ## 关键文件 ```text BiddingAgent/ ├── app/ │ ├── main.py # 应用入口:初始化配置、日志、数据库和调度器 │ ├── config/ │ │ ├── settings.py # 读取 .env 与 config.yaml,组装运行配置 │ │ └── config.yaml # 非敏感业务配置:抓取页数、关键词、日志、调度周期 │ ├── crawler/ │ │ ├── bid_spider.py # 招标页面解析:提取项目标题、编号、时间、链接、附件 │ │ └── playwright_client.py # Playwright 浏览器封装:打开动态页面、翻页、滚动 │ ├── workflow/ │ │ ├── graph.py # LangGraph 主流程:抓取、去重、分析、通知、落库 │ │ └── state.py # 工作流状态结构 │ ├── llm/ │ │ └── deepseek_client.py # DeepSeek API 调用与投标推荐 JSON 解析 │ ├── tools/ │ │ ├── notify_tool.py # 企业微信机器人通知 │ │ ├── download_tool.py # 附件下载工具,当前预留扩展 │ │ └── retry_tool.py # 通用 retry 装饰器 │ ├── scheduler/ │ │ └── jobs.py # APScheduler 定时任务注册 │ ├── db/ │ │ ├── database.py # SQLite 初始化、项目入库、状态更新、查询 │ │ └── models.py # BidProject、BidAnalysis 等数据模型 │ ├── logs/ # 运行日志与临时测试报告,已被 Git 忽略 │ └── utils/ │ ├── logger.py # 标准 logging + 滚动文件日志 │ └── helpers.py # 文本清洗、日期/编号提取、URL 和 hash 工具 ├── tests/ │ └── crawler_smoke_test.py # 轻量爬虫测试:只抓取并打印/导出 Markdown ├── requirements.txt # Python 依赖 ├── .env.example # 不含密钥的环境变量模板 ├── .env # API Key、Webhook 等敏感配置,本地使用,已被 Git 忽略 ├── start.bat # Windows 启动脚本 ├── run_once.bat # Windows 单次执行脚本,供任务计划程序调用 ├── main.py # 根入口转发到 app.main └── README.md ``` ## Windows 10 部署 推荐使用“Gitee 克隆源码 + Windows 本机虚拟环境 + 任务计划程序”。不要复制开发电脑的 `.venv`,也不建议打包为单文件 EXE。 当前配置使用搜索 API 且 `crawler.fetch_details: false`,不需要安装 Playwright Chromium,适合老旧电脑。 ### 1. 安装 Git 和 Python 在 PowerShell 中执行: ```powershell winver winget --version winget install --id Git.Git -e --source winget --accept-source-agreements --accept-package-agreements winget install 9NQ7512CXL7T -e --accept-package-agreements --disable-interactivity ``` 关闭并重新打开 PowerShell,然后配置 Python Install Manager、安装 Python 3.14,并将 Python 全局命令目录添加到当前用户的 `PATH`: ```powershell pymanager install --configure -y pymanager install 3.14 $pythonBin = "$env:LOCALAPPDATA\Python\bin" $userPath = [Environment]::GetEnvironmentVariable("Path", "User") $newUserPath = @($userPath -split ";" | Where-Object { $_ }) + $pythonBin [Environment]::SetEnvironmentVariable("Path", (($newUserPath | Select-Object -Unique) -join ";"), "User") ``` 使用 `pymanager` 可以避免旧版 Python Launcher 抢占 `py` 命令,导致 `py install 3.14` 报错。更新 `PATH` 后关闭并重新打开 PowerShell,再执行: ```powershell git --version py -V:3.14 --version python3.14 --version ``` 没有 `winget` 时可手动安装: - Python:https://www.python.org/downloads/ - Git for Windows:https://git-scm.com/install/windows ### 2. 克隆项目 仓库地址: ```text https://gitee.com/automatic_aiming/bidding-agent.git ``` 私有仓库首次克隆时需要输入有访问权限的 Gitee 账号凭据: ```powershell Set-Location C:\ git clone https://gitee.com/automatic_aiming/bidding-agent.git C:\BiddingAgent Set-Location C:\BiddingAgent ``` ### 3. 创建虚拟环境 ```powershell python -m venv .venv .\.venv\Scripts\python.exe -m pip install --upgrade pip .\.venv\Scripts\python.exe -m pip install -r requirements.txt ``` ### 4. 配置密钥 ```powershell Copy-Item .env.example .env notepad .env ``` 至少填写: ```env DEEPSEEK_API_KEY=替换为真实密钥 WECHAT_WEBHOOK_URL=替换为真实企业微信机器人Webhook ``` `.env` 包含敏感信息,已被 Git 忽略,不要提交到仓库。业务筛选、团队资质和执行时间在 `app/config/config.yaml` 中维护。 ### 5. 首次验证 ```powershell .\.venv\Scripts\python.exe -m unittest discover -s tests -p "test_*.py" .\run_once.bat Get-Content .\app\logs\bidding_agent.log -Tail 100 ``` 确认企业微信群收到消息,并检查以下文件已经创建: ```text app/db/bidding_agent.sqlite3 app/logs/bidding_agent.log ``` ### 6. 创建计划任务 老旧电脑推荐每天执行两次 `run_once.bat`,不让程序全天驻留: ```powershell schtasks /Create /TN "BiddingAgent-0900" /TR "cmd.exe /c C:\BiddingAgent\run_once.bat" /SC DAILY /ST 09:00 /F schtasks /Create /TN "BiddingAgent-1400" /TR "cmd.exe /c C:\BiddingAgent\run_once.bat" /SC DAILY /ST 14:00 /F schtasks /Query /TN "BiddingAgent-0900" schtasks /Query /TN "BiddingAgent-1400" ``` 立即执行/删除定时任务 ```powershell schtasks /Run /TN "BiddingAgent-0900" schtasks /Run /TN "BiddingAgent-1400" schtasks /Delete /TN "BiddingAgent-0900" schtasks /Delete /TN "BiddingAgent-1400" ``` 只有需要 HTTP 立即触发接口时才使用 `start.bat` 常驻运行,并配置 `TRIGGER_API_TOKEN` 与防火墙。否则保持 `.env` 中: ```env TRIGGER_API_ENABLED=false ``` ### 7. 更新与备份 拉取更新: ```powershell Set-Location C:\BiddingAgent git pull --ff-only origin main .\.venv\Scripts\python.exe -m pip install -r requirements.txt .\run_once.bat ``` 备份历史数据时,先确认任务没有运行: ```powershell New-Item -ItemType Directory -Force C:\BiddingAgentBackup Copy-Item C:\BiddingAgent\app\db\bidding_agent.sqlite3 C:\BiddingAgentBackup\bidding_agent.sqlite3 ``` ## 配置 敏感配置保存在 `.env`: ```env DEEPSEEK_API_KEY= DEEPSEEK_BASE_URL=https://api.deepseek.com DEEPSEEK_MODEL=deepseek-chat WECHAT_WEBHOOK_URL= TRIGGER_API_ENABLED=false TRIGGER_API_TOKEN= ``` 主要业务配置保存在 `app/config/config.yaml`: - `crawler.max_projects` / `max_pages`:每轮抓取数量和页数。 - `scheduler.run_times`:常驻模式的每日执行时间。 - `deepseek.team_qualifications`:团队持有资质。 - `deepseek.team_strengths`:团队擅长方向。 - `deepseek.exclude_keywords`:命中后直接排除的关键词。 - `deepseek.minimum_recommendation_score`:直接推荐最低分,当前为 `80`。 - `notification.high_priority_score`:企业微信直接推送最低分。 - `logging`:日志路径和滚动策略。 ## 常用命令 Windows: ```powershell # 初始化数据库 .\.venv\Scripts\python.exe -m app.main --init-db # 执行一次完整任务 .\run_once.bat # 常驻运行调度器和 HTTP 接口 .\start.bat # 查看最近日志 Get-Content .\app\logs\bidding_agent.log -Tail 100 ``` 开发与测试: ```bash # 所有单元测试 python -m unittest discover -s tests -p "test_*.py" # 只测试抓取 python -m tests.crawler_smoke_test --pages 1 --limit 10 # 测试 DeepSeek 分析但不推送 python -m tests.deepseek_recommendation_test --pages 1 --analyze-limit 5 --dry-run # 只在控制台打印 DeepSeek 推荐结果,不发送企微通知、不生成留档 python -m tests.console_recommendation_test ``` ## SQLite 数据库 SQLite 是嵌入式文件数据库,不需要像 MySQL 一样安装数据库服务。Python 自带项目所需的 `sqlite3` 模块。 程序每次启动时都会自动: - 创建 `app/db/` 目录和 `bidding_agent.sqlite3` 文件。 - 创建 `bid_projects`、`bid_analysis_history` 表和相关索引。 - 保留已有数据库和历史数据。 数据库不会通过 Gitee 同步。新电脑默认创建空数据库,需要保留旧数据时应单独复制数据库文件。 当前初始化逻辑只会创建缺失的表和索引。未来修改已有表字段时,需要先备份并编写数据库迁移脚本。 ### 查看 SQLite 旧电脑推荐使用 [DB Browser for SQLite](https://sqlitebrowser.org/dl/): ```powershell winget install -e --id DBBrowserForSQLite.DBBrowserForSQLite ``` 安装后打开: ```text C:\BiddingAgent\app\db\bidding_agent.sqlite3 ``` 其他工具: - [SQLiteStudio](https://www.sqlitestudio.pl/):轻量、免安装。 - [DBeaver Community](https://dbeaver.io/download/):功能完整,但资源占用更高。 常用查询: ```sql SELECT bid_number, title, deadline, recommended, analysis_status, notification_status, updated_at FROM bid_projects ORDER BY updated_at DESC LIMIT 50; SELECT project_key, recommended, analysis_status, analyzed_at FROM bid_analysis_history ORDER BY analyzed_at DESC LIMIT 50; ``` 查看生产数据库时建议只执行查询。修改或删除数据前,应先停止任务并备份数据库文件。 ## 排查问题 | 现象 | 优先检查 | | --- | --- | | 启动失败或配置未生效 | `.env`、`app/config/config.yaml`、`app/logs/bidding_agent.log` | | 爬不到项目 | 网络连接、搜索 API、`app/crawler/bid_spider.py` | | DeepSeek 分析失败 | `.env` 中的 API Key、网络连接、日志 | | 企业微信没有收到消息 | `WECHAT_WEBHOOK_URL`、日志 | | 计划任务未执行 | Windows 任务计划程序历史、`run_once.bat`、日志 | | 数据库需要检查 | `app/db/bidding_agent.sqlite3` |