Skip to content

Commit 34cc87b

Browse files
committed
feat: 文章抓取模块 + 工程化工具链 (v1.2.1)
- feat: 新增 article_grab/ 模块 — trafilatura + httpx 正文提取,维基百科 API 适配器(反爬 403 自动走官方 REST API,7 语言) - feat: 文章抓取 PDF 日报(--pdf)— 封面/目录/分节,防文字挤压排版 - test: 26 个 pytest 用例(单元+集成,PDF 重叠检测、HTTP mock、维基适配器),覆盖率 80.94% - build: pyproject.toml(ruff/black/mypy strict)+ pre-commit + GitHub Actions CI(3.10/3.13 矩阵) - style: 全项目 black 格式化 + ruff 修复(历史代码按目录豁免 BLE001 设计意图) - docs: CHANGELOG v1.2.1 + README 更新
1 parent 024d288 commit 34cc87b

35 files changed

Lines changed: 2259 additions & 508 deletions

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
quality:
11+
name: Lint + Type + Test
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.10", "3.13"]
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
cache: pip
23+
24+
- name: 安装依赖
25+
run: |
26+
pip install -e ".[dev]"
27+
pip install pymupdf
28+
29+
- name: 安装中文字体(Linux CI 无 Windows 字体)
30+
run: |
31+
sudo apt-get update -qq
32+
sudo apt-get install -y -qq fonts-noto-cjk
33+
34+
- name: Lint (ruff)
35+
run: ruff check .
36+
37+
- name: Format 检查 (black)
38+
run: black --check .
39+
40+
- name: 类型检查 (mypy)
41+
run: mypy article_grab
42+
43+
- name: 单元 + 集成测试 + 覆盖率门禁
44+
run: |
45+
pytest tests --cov=article_grab \
46+
--cov-report=term --cov-fail-under=80
47+
48+
- name: 上传覆盖率报告 (Codecov)
49+
if: ${{ matrix.python-version == '3.13' }}
50+
uses: codecov/codecov-action@v4
51+
with:
52+
fail_ci_if_error: false

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ Thumbs.db
2626
*.egg-info/
2727
.env
2828
venv/
29+
30+
# 测试/工具链缓存
31+
.pytest_cache/
32+
.mypy_cache/
33+
.ruff_cache/
34+
.coverage
35+
htmlcov/
36+
37+
# 文章抓取产物
38+
out/

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# pre-commit 配置:提交前自动 lint / format / 类型检查
2+
# 安装:pip install pre-commit && pre-commit install
3+
repos:
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.6.9
6+
hooks:
7+
- id: ruff
8+
- id: ruff-format
9+
10+
- repo: https://github.com/pre-commit/mirrors-mypy
11+
rev: v1.11.2
12+
hooks:
13+
- id: mypy
14+
additional_dependencies: [httpx, trafilatura, fpdf2]
15+
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.6.0
18+
hooks:
19+
- id: trailing-whitespace
20+
- id: end-of-file-fixer
21+
- id: check-yaml
22+
- id: check-added-large-files

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
本项目使用 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 格式。
44

5+
## [v1.2.1] - 2026-08-13
6+
7+
### 新增
8+
- feat: 文章抓取模块(`article_grab/`)— trafilatura + httpx 正文提取(标题/作者/日期/站点/正文),请求重试 + 真实浏览器头,文件名净化(防路径穿越)
9+
- feat: **维基百科 API 适配器** — 词条页 HTML 反爬 403 时自动走官方 REST API(支持 zh/en/ja/fr/de/ru/es 7 语言)
10+
- feat: 文章抓取 PDF 日报(`article_grab/grabber.py --pdf`)— 封面/目录/分节,中文字体自动适配,防文字挤压排版(中英分段换行 + 超长 URL 逐字符硬断)
11+
- test: 26 个 pytest 用例(单元 + 集成,含 PDF 重叠/溢出逐词检测、维基 API 适配器、HTTP mock 替身)
12+
13+
### 工程化
14+
- build: `pyproject.toml`(ruff/black/mypy strict/pytest + setuptools 显式模块声明)
15+
- build: `.pre-commit-config.yaml` 提交前自动检查
16+
- build: `.github/workflows/ci.yml` — GitHub Actions(Python 3.10/3.13 矩阵:lint→format→mypy→test+cov≥80%)
17+
18+
### 修复
19+
- fix: trafilatura 2.2 API 变更(`extract_metadata` 参数 `url``default_url`
20+
- fix: 正文丢失 — 按「原文链接」内容匹配回填元数据
21+
- fix: PDF 换行符缺字形 — 按段落渲染正文
22+
- fix: 裸 `except Exception: pass` 吞异常 — 引入 logging + 收窄异常类型
23+
- fix: 中文字体跨平台查找(Windows/Linux/macOS 候选),CI 安装 fonts-noto-cjk
24+
525
## [v1.2.0] - 2026-08-13
626

727
### 新增

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
77

88
**多源报告汇总推送工具** — Windows 桌面应用,一站式聚合 **7 大类信息源** 的报告与数据,
9-
自动生成 **TXT / PDF 学术风格报告**。内置日报本地生成服务、Windows XP 复古主题与自定义背景。
9+
自动生成 **TXT / PDF 学术风格报告**。内置日报本地生成服务、文章抓取模块(trafilatura + 维基 API)、Windows XP 复古主题与自定义背景。
1010

1111
> ⚠️ 本项目仅供学习研究使用,抓取行为请遵守各站点 robots 协议与相关法律法规。
1212
@@ -54,6 +54,22 @@
5454
- **日报本地生成服务**:设置每日生成时间(默认 09:00)+ 多选信息源模块 + 输出目录 → 每天到点后台自动抓取并生成 `daily_report_YYYYMMDD.txt/.pdf`,每日自动去重,界面实时显示生成状态与文件路径,支持「立即生成一次」
5555
- **Windows XP (Luna) 复古主题**:经典蓝色渐变标题栏、XP 式圆角渐变按钮、米色面板、Tahoma/宋体字体体系
5656

57+
### 文章抓取模块(v1.2.1 新增)
58+
59+
命令行抓取任意文章网页 → 提取正文 → Markdown / PDF 日报:
60+
61+
```bash
62+
# 抓取单篇文章(输出 out/<站点>_<日期>_<标题>.md)
63+
E:\Anaconda3-2026\python.exe -m article_grab.grabber https://example.com/article
64+
65+
# 批量 + 生成 PDF 日报
66+
E:\Anaconda3-2026\python.exe -m article_grab.grabber --file urls.txt --pdf
67+
```
68+
69+
- **正文提取**:trafilatura 自动剥离导航/广告/页脚,提取标题/作者/日期/站点
70+
- **维基百科**:词条页自动走官方 REST API(页面 HTML 反爬 403 时依然可用,支持 7 种语言)
71+
- **PDF 日报**:封面/目录/分节,中文字体自动适配,防文字挤压(0 重叠 0 溢出)
72+
5773
## 快速开始
5874

5975
### 方式一:直接运行 EXE
@@ -86,12 +102,21 @@ MultiSourceReportTool/
86102
│ └── app_icon.ico # 应用图标
87103
├── ui/
88104
│ ├── main_window.py # 主窗口(导航/路由/背景)
89-
│ ├── styles.py # 全局 QSS 样式
105+
│ ├── styles.py # 全局 QSS 样式(XP 主题)
106+
│ ├── daily_service.py # 日报本地生成服务
90107
│ └── pages/ # 7 个信息源页面
108+
├── article_grab/ # 文章抓取模块(v1.2.1)
109+
│ ├── grabber.py # 正文提取(httpx + trafilatura + 维基 API)
110+
│ ├── pdf_daily.py # PDF 日报生成(防挤压排版)
111+
│ └── __init__.py
91112
├── fetchers/ # 7 个数据抓取器
92-
└── report/
93-
├── txt_writer.py # TXT 报告生成
94-
└── pdf_writer.py # PDF 学术风格报告 (fpdf2)
113+
├── report/
114+
│ ├── txt_writer.py # TXT 报告生成
115+
│ └── pdf_writer.py # PDF 学术风格报告 (fpdf2)
116+
├── tests/ # pytest 测试套件(26 用例)
117+
├── pyproject.toml # ruff/black/mypy/pytest 配置
118+
├── .github/workflows/ # GitHub Actions CI
119+
└── .pre-commit-config.yaml
95120
```
96121

97122
## 修改日志

article_grab/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""文章抓取模块 — 正文提取 + PDF 日报生成(MultiSourceReportTool v1.2.1 新增)。"""
2+
3+
from .grabber import fetch_page, fetch_wikipedia, grab # noqa: F401
4+
from .pdf_daily import generate_daily_pdf # noqa: F401
5+
6+
__all__ = ["grab", "fetch_page", "fetch_wikipedia", "generate_daily_pdf"]

0 commit comments

Comments
 (0)