Files
intl_news/README.md
T
simon d4a55bcaaa feat: M9 日报结构化入库(HTML 改为写入 MySQL news_report/news_event,report_type=intl)
- 新增 report_db/ 包(models/schema/db,复用 news 项目实现,幂等 upsert)
- reporter.py: _build_report_data + generate_report 写库返回 report_id
- pipeline/cli 适配 report_id 返回值;HTML 渲染/上传保留 deprecated
- 新增 tests/test_report_db.py;.env.example 增加 NEWS_DB_* 配置
- 已部署 pi5 并验证:真实生成 report_id=184(12 事件)+ 幂等覆盖
2026-08-04 11:09:17 +08:00

225 lines
7.2 KiB
Markdown
Raw 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.
# English Financial News
国际财经新闻私有化 Deep Research 平台。
## 核心能力
- **M1** 英文财经新闻抓取(Crawl4AIheadful Playwright + HTTP 代理,13 个源)
- **M2** 英文正文提取(trafilatura
- **M3** 三层去重(URL Hash / 内容 Hash / SimHash 模糊)
- **M4** 全文英译中 + 投资事件抽取(LLM DeepSeek v4-flash
- **M5** 向量生成(DashScope text-embedding-v31024 维)
- **M6** 双语向量知识库(Qdrant
- **M7** 定时调度(06/12/18/22 + 每日 AI 摘要日报(M9 起结构化写入 MySQL,不再产出 HTML)
- **M8** MCP 服务(Cherry Studio / Claude Code Agent 深度研究)
## 部署架构
```
国内服务器(Pi 4, 8GB
┌──────────────────────────────────────┐
│ M1 抓取(headful Playwright
│ HTTP 代理 → Privoxy → SOCKS5 │
│ ↓ │
│ M2 正文提取 → M3 去重 │
│ ↓ │
│ M4 翻译+事件抽取(DeepSeek
│ ↓ │
│ M5 向量生成 → M6 Qdrant 入库 │
│ ↓ │
│ 日报生成 → 写入 MySQLnews_report
│ ↓ │
│ M8 MCP 服务(研究 Agent
└──────────────────────────────────────┘
```
> 海外服务器已于 2026-07-14 停用,全链路在 Pi 独立运行。
---
## 新闻源状态(2026-07-23
| 源 | ID | 策略 | 日产量 | 状态 |
|----|----|------|--------|------|
| Reuters | `reuters` | Google News RSS | ~30 篇摘要 | ⚠️ DataDome |
| CNBC | `cnbc` | CNBC RSS | ~25 篇 | ✅ |
| MarketWatch | `marketwatch` | RSS + stealth | ~25 篇 | ✅ |
| Financial Times | `ft` | FT RSS | ~20 篇摘要 | ⚠️ 付费墙 |
| Yahoo Finance | `yahoo_finance` | Yahoo RSS | ~30 篇 | ✅ |
| **Investing.com** | `investing` | **Google News RSS** + stealth | **25 篇摘要** | **✅ 2026-07-23 修复** |
| Seeking Alpha | `seekingalpha` | RSS + stealth | ~20 篇 | ✅ |
| Barron's | `barrons` | Dow Jones RSS + stealth | ~20 篇 | ✅ |
| WSJ | `wsj` | Dow Jones RSS + stealth | ~20 篇 | ✅ |
| Economist | `economist` | RSS + stealth | ~15 篇 | ✅ |
| **InvestingLive** | `investinglive` | **RSS(全文)** | **25 篇** | **✅ 2026-07-23 新增** |
| ZeroHedge | `zerohedge` | FeedBurner RSS | ~15 篇全文 | ✅ |
| ~~ForexLive~~ | ~~forexlive~~ | ~~已迁移~~ | ~~0~~ | ~~❌ 301→investinglive~~ |
> **注:** RSS 摘要源的全文通过 headful Playwright + HTTP 代理回退抓取。当前国内服务器使用 Shadowsocks + Privoxy 代理访问海外。
---
## 快速开始
### 环境要求
- Python 3.11
- uv
- XvfbPi 服务器 headful 模式需要)
- Shadowsocks 客户端 + Privoxy(国内服务器海外代理)
### 安装
```bash
# 创建虚拟环境并安装依赖
uv sync
# 配置环境变量
cp .env.example .env
# 编辑 .env 填入真实 API KeyDeepSeek / DashScope / Qdrant
```
### Pi 服务器前置条件
```bash
# 1. Xvfb 虚拟显示器(headful Playwright 需要)
sudo apt install xvfb
Xvfb :99 -screen 0 1280x1024x24 -ac +extension RANDR &
# 2. Shadowsocks + PrivoxyHTTP 代理访问海外)
sudo apt install shadowsocks-libev privoxy
# 配置 /etc/shadowsocks-libev/config.json(服务端信息)
# 配置 /etc/privoxy/configforward-socks5t 127.0.0.1:1088 .
sudo systemctl enable --now shadowsocks-libev-local
sudo systemctl enable --now privoxy
```
---
## 操作命令
### 全流程自动化
```bash
# 全流程:M1 抓取 → M2→M6 管道 → 日报
# 每天 06:00 / 12:00 / 18:00 / 22:00 自动执行
bash scripts/domestic_full.sh
```
### 单步执行
```bash
# M1 抓取全部源(headful + HTTP 代理)
bash scripts/domestic_crawl_8g.sh
# M1 单源测试
bash scripts/domestic_crawl_8g.sh investing
bash scripts/domestic_crawl_8g.sh investinglive
# M2→M6 管道(需先有 raw 数据)
bash scripts/pipeline.sh
# 仅生成日报(写入 MySQL news_report/news_eventreport_type="intl"
uv run en-news report
```
### 调度查看
```bash
# 查看最近日志
tail -50 logs/full.log
# 查看日报
ls -lt data/reports/
```
---
## 配置说明
| 文件 | 用途 |
|------|------|
| `configs/sources.yaml` | 英文财经新闻源定义(13 个源) |
| `configs/system.yaml` | 系统级业务参数(超时/并发/LLM 模型等) |
| `configs/profiles/8g_headful.yaml` | Pi 服务器 headful 抓取配置(代理/超时) |
| `.env` | 密钥 / 服务地址(不入 Git) |
| `prompts/` | LLM Prompt 模板(翻译/日报/搜索 Agent |
### 日报入库(M9
日报内容结构化写入与 [news 项目](https://github.com/) 共用的 MySQL `myquant` 库(表 `news_report` / `news_event``report_type="intl"`,同一天重复生成幂等覆盖)。表结构与数据契约见 news 项目 `docs/db_schema.md`
`.env` 需配置(与 news 项目 `.env``NEWS_DB_PASSWORD` 相同):
```env
NEWS_DB_HOST=192.168.1.10 # pi5 经内网直连 pi 上的 autossh 隧道(0.0.0.0:13306 → doorcome.cn:3306
NEWS_DB_PORT=13306
NEWS_DB_USER=myquant
NEWS_DB_PASSWORD=xxx
NEWS_DB_NAME=myquant
```
---
## 数据存储
```
data/
├── raw/{source_id}/{yyyymmdd}/ M1 原始抓取(HTML + Markdown
├── processed/{source_id}/ M2 正文提取结果
├── dedup/ M3 去重指纹库(SQLite
├── translations/{yyyymmdd}/ M4 翻译+事件抽取结果(JSONL)
├── embeddings/{yyyymmdd}/ M5 向量文件(JSONL
├── reports/ M7 日报(M9 起不再产出 HTML,改存 MySQL
└── vectorstore/ M6 Qdrant 数据
```
Qdrant collection 名称:`en_finance_news`
---
## MCP 服务
M8 模块提供 MCPModel Context Protocol)服务,供 Cherry Studio / Claude Code 等客户端接入进行深度研究。
```bash
# 启动 MCP 服务
uv run en-news mcp-server
```
支持的工具:
| Tool | 功能 |
|------|------|
| `en_news_search` | 语义搜索知识库 |
| `en_news_filter` | 按源/日期/情绪筛选 |
| `en_news_trending` | 获取热点事件 |
| `en_news_report` | 获取最新日报 |
| `en_news_daily_brief` | 一键生成简报 |
---
## 常见问题
### 为什么有些源只拿到摘要?
部分网站有强反爬(Cloudflare/DataDome/付费墙),RSS 只返回摘要。全文可尝试 headful 浏览器回退,但成功率取决于代理线路质量。
### 日报存在哪里?
M9 起日报结构化写入 MySQL `myquant` 库:主表 `news_report``report_type="intl"`+ 明细表 `news_event``section="intl"`),数据契约与 [news 项目](https://github.com/) 一致(见其 `docs/db_schema.md`)。历史 HTML 日报(2026-06-16 ~ 2026-08-03)已由 news 项目解析导入。API / 前端读取同一批表。
### 如何添加新源?
编辑 `configs/sources.yaml`,添加源配置(id/name/homepage/rss_url/article_url_pattern 等)。参考现有源格式。
---
## 项目计划
详见 [english-news-plan.md](english-news-plan.md)
## 许可证
MIT