Skip to content

hgzzd/AI_RSS_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSS API

让大模型通过工具调用获取 RSS 订阅文章的完整内容。


前置要求

  • Python 3.7 或更高版本
  • 能运行命令行的终端(Terminal、CMD、PowerShell 等)

检查 Python 是否已安装:

python3 --version

如果显示版本号(如 Python 3.10.12),说明已安装。


第一步:准备项目文件

项目需要以下文件:

接口/
├── main.py           # 主程序
├── opml.opml         # RSS 订阅源文件
├── requirements.txt  # 依赖列表
├── AI_API_GUIDE.md   # AI 使用指南(给大模型读的文档)
└── README.md         # 本文档

如果文件齐全,跳到第二步。


第二步:安装依赖

依赖是程序运行需要的外部库,需要先安装。

Windows 用户

pip install -r requirements.txt

Linux / macOS 用户

pip3 install -r requirements.txt

安装过程需要几十秒,看到类似以下输出说明成功:

Successfully installed fastapi uvicorn feedparser aiohttp beautifulsoup4 xmltodict

第三步:准备 OPML 文件

OPML 文件包含你的 RSS 订阅源列表。

如果你有 Fluent Reader

  1. 打开 Fluent Reader
  2. 点击 文件导出订阅源为 OPML
  3. 将导出的文件重命名为 opml.opml
  4. 放到项目目录(和 main.py 同一文件夹)

如果你有其他 RSS 阅读器

导出 OPML 文件,放到项目目录并命名为 opml.opml

如果你没有 OPML 文件

项目目录中已有一个示例文件可以直接使用。


第四步:启动服务

Windows 用户

python main.py

Linux / macOS 用户

python3 main.py

启动后会看到:

Loaded 100 feeds from OPML
  Fetching: 文章标题...
  Fetching: 文章标题...
  ...
Fetched 500 articles
INFO:     Uvicorn running on http://0.0.0.0:8000

等待看到 Uvicorn running 这行后,服务就启动成功了。

首次启动需要 1-2 分钟抓取文章内容,期间请保持终端开启。


第五步:测试 API

方法一:浏览器测试(最简单)

打开浏览器,访问:

http://localhost:8000/categories

应该能看到分类列表的 JSON 数据。

方法二:curl 命令测试

新的终端窗口(不要关闭运行服务的终端)输入:

# 获取分类
curl "http://localhost:8000/categories"

# 获取文章
curl "http://localhost:8000/articles?limit=3"

方法三:API 文档页面

浏览器访问:

http://localhost:8000/docs

这是 FastAPI 自动生成的交互式文档,可以直接在网页上测试所有接口。


API 使用说明

基础用法

功能 命令
获取所有文章 curl "http://localhost:8000/articles"
获取 10 篇文章 curl "http://localhost:8000/articles?limit=10"
获取分类列表 curl "http://localhost:8000/categories"
获取订阅源列表 curl "http://localhost:8000/feeds"
获取单篇文章 curl "http://localhost:8000/articles/1"
仅获取摘要(不含正文) curl "http://localhost:8000/articles?mode=summary&limit=10"

按分类筛选

curl "http://localhost:8000/articles?category=L1%20-%20AI%20Core"

注意:分类名称中的空格需要用 %20 替代(URL 编码)

获取单篇文章

每篇文章都有唯一 ID,可以直接获取:

curl "http://localhost:8000/articles/36"

模式选择(摘要 vs 全文)

  • mode=full(默认):返回完整文章内容,包含 content 字段
  • mode=summary:仅返回摘要,不含 content 字段,数据量更小
# 获取全文
curl "http://localhost:8000/articles?mode=full&limit=5"

# 仅获取摘要
curl "http://localhost:8000/articles?mode=summary&limit=50"

返回数据格式

[
  {
    "id": 1,
    "title": "文章标题",
    "url": "https://原文链接",
    "content": "完整的文章正文内容...",
    "summary": "文章摘要",
    "author": "作者名",
    "published": "2026-02-09T10:00:00Z",
    "source": "RSS源名称",
    "category": "分类名称"
  }
]

让大模型调用这个 API

方法一:直接提供 AI_API_GUIDE.md

项目包含一份专门给大模型阅读的 API 文档 AI_API_GUIDE.md,在对话中提供给大模型:

请阅读 /home/adduser/idea/接口/AI_API_GUIDE.md

然后帮我:
1. 获取最新的技术文章
2. 筛选重要内容
3. 生成每日简报

方法二:在 Claude / ChatGPT 中手动说明

在对话中提供以下信息:

我有一个本地运行的 API 服务,地址是 http://localhost:8000

API 端点:
- GET /articles - 获取文章列表
- GET /articles/{id} - 获取单篇文章全文
- GET /articles?category=分类名 - 按分类筛选
- GET /articles?limit=数字 - 限制返回数量
- GET /articles?mode=summary - 仅获取摘要(不含正文)

返回数据包含:id、title、content、summary、url、author、published、source、category 等字段

请帮我调用这个 API 获取最新文章,并总结内容。

方法三:作为工具函数配置

如果使用支持工具调用的大模型,可以配置如下:

{
  "name": "get_rss_articles",
  "description": "获取 RSS 订阅中的技术文章",
  "url": "http://localhost:8000/articles",
  "method": "GET",
  "parameters": {
    "category": "文章分类(可选)",
    "limit": "返回数量,默认 50",
    "mode": "summary(仅摘要)或 full(含全文,默认)"
  }
}

定时任务示例(crontab)

# 每天早上 8 点生成简报
0 8 * * * cd /home/adduser/idea/接口 && cat AI_API_GUIDE.md | claude-code "阅读这份API文档,帮我获取今天的AI相关文章并生成简报"

常见问题

Q: 启动后提示 "No module named xxx"

A: 依赖没安装成功,重新运行:

pip install -r requirements.txt

Q: 启动后卡住不动

A: 正在抓取文章内容,首次启动需要 1-2 分钟,等待看到 Uvicorn running 提示。

Q: 浏览器访问显示 "无法访问此网站"

A: 确认服务已启动(终端显示 Uvicorn running),检查地址是否为 http://localhost:8000(不是 https)。

Q: 想要停止服务

A: 在运行服务的终端窗口按 Ctrl + C

Q: 如何更新文章内容

A: 在浏览器或终端访问:

curl -X POST "http://localhost:8000/refresh"

项目依赖

用途
FastAPI Web 框架
uvicorn 服务器
feedparser 解析 RSS
aiohttp 异步 HTTP 请求
beautifulsoup4 解析 HTML 提取正文
xmltodict 解析 OPML 文件

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages