用途
Blogwatcher 是一个 RSS/Atom 订阅源监控技能,用于监控博客和订阅源的新内容,并在有更新发布时发出通知。
主要能力
- RSS/Atom 解析:同时支持 RSS 2.0 和 Atom 格式的订阅源。
- 更新检测:跟踪已读条目并检测新发布的文章。
- 内容过滤:可按关键词、作者或分类进行过滤。
- 通知集成:可通过 Telegram、Discord、Slack 或邮件发送更新。
- 持久化状态:保存已读条目,重启后仍可保留。
- 定时监控:可按 cron 计划检查订阅源。
安装
安装所需依赖:
npm install feedparser
配置
在 config/feeds.json 创建订阅源配置文件,示例:
{
"feeds": [
{
"name": "Tech Crunch",
"url": "https://techcrunch.com/feed/",
"check_interval": "*/30 * * * *",
"filters": {
"keywords": ["AI", "startup", "funding"],
"min_length": 100
},
"notifications": {
"telegram": true,
"discord": false
}
},
{
"name": "Hacker News",
"url": "https://hnrss.org/frontpage",
"check_interval": "*/15 * * * *",
"filters": {
"keywords": ["show hn", "launch"]
}
}
]
}
使用方式
API
监控单个订阅源:
const { watchFeed } = require('./blogwatcher');
const updates = await watchFeed({
url: 'https://example.com/feed.xml',
name: 'Example Blog'
});
console.log(`Found ${updates.length} new posts`);
for (const post of updates) {
console.log(`- ${post.title} (${post.link})`);
}
检查所有已配置的订阅源:
const { checkAllFeeds } = require('./blogwatcher');
const results = await checkAllFeeds();
// Returns: { feeds: [...], total_updates: N }
获取订阅源历史:
const { getFeedHistory } = require('./blogwatcher');
const history = getFeedHistory('tech-crunch');
console.log(`Seen ${history.length} posts from Tech Crunch`);
输出格式
每条更新包含:
{
"feed_name": "Tech Crunch",
"title": "Startup Raises $10M Series A",
"link": "https://techcrunch.com/2026/...",
"published": "2026-02-25T10:00:00Z",
"author": "John Doe",
"summary": "A startup has raised...",
"categories": ["AI", "Funding"],
"content": "Full article content...",
"detected_at": "2026-02-25T13:00:00Z"
}
过滤
关键词过滤:
{
"filters": {
"keywords": ["AI", "machine learning"],
"match_any": true
}
}
作者过滤:
{
"filters": {
"authors": ["John Doe", "Jane Smith"]
}
}
分类过滤:
{
"filters": {
"categories": ["Technology", "Startups"]
}
}
内容长度过滤:
{
"filters": {
"min_length": 200,
"max_length": 5000
}
}
通知
Telegram:
const { sendTelegramNotification } = require('./blogwatcher');
await sendTelegramNotification({
chat_id: process.env.TELEGRAM_CHAT_ID,
updates: [...]
});
Discord Webhook:
await sendDiscordNotification({
webhook_url: 'https://discord.com/api/webhooks/...',
updates: [...]
});
CLI 用法
# 检查所有已配置的订阅源
blogwatcher check
# 检查指定订阅源
blogwatcher check --url https://example.com/feed.xml
# 显示订阅源历史
blogwatcher history --feed "tech-crunch"
# 清除已读条目
blogwatcher clear --feed "tech-crunch"
# 测试通知
blogwatcher test-notify --feed "tech-crunch"
状态管理
已读条目存储在 data/blogwatcher-seen.json:
{
"tech-crunch": [
"https://techcrunch.com/2026/02/25/post-1",
"https://techcrunch.com/2026/02/24/post-2"
],
"hacker-news": [...]
}
每个订阅源最大条目数:1000(可配置)。
最佳实践
- 尊重速率限制:使用合适的 check_interval(通常 15-30 分钟)。
- 积极过滤:仅对真正相关的内容发送通知。
- 监控订阅源健康:检查订阅源错误和失效 URL。
- 去重:使用基于链接的去重(而非基于标题)。
- 归档重要文章:将关键更新保存到永久存储。
完整监控示例
const { watchFeed, sendTelegramNotification } = require('./blogwatcher');
async function monitorFeeds() {
const feeds = [
{
name: 'AI Weekly',
url: 'https://aiweekly.co/feed/',
filters: { keywords: ['agent', 'LLM'] }
},
{
name: 'Developer News',
url: 'https://devnews.io/rss',
filters: { keywords: ['JavaScript', 'TypeScript'] }
}
];
for (const feed of feeds) {
try {
const updates = await watchFeed(feed);
if (updates.length > 0) {
console.log(`[${feed.name}] Found ${updates.length} new posts`);
await sendTelegramNotification({
chat_id: process.env.TELEGRAM_CHAT_ID,
message: `📰 ${feed.name} has ${updates.length} new posts:\n\n` +
updates.slice(0, 5).map(u => `• ${u.title}\n${u.link}`).join('\n')
});
}
} catch (error) {
console.error(`[${feed.name}] Error: ${error.message}`);
}
}
}
setInterval(monitorFeeds, 30 * 60 * 1000);
错误处理
该技能处理常见订阅源错误:
- HTTP 404:订阅源 URL 未找到——标记为不活跃。
- HTTP 429:被限流——退避后稍后重试。
- 无效 XML:订阅源格式错误——记录并跳过。
- 超时:订阅源响应过慢——跳过本次检查。
适用场景
适用于需要持续跟踪多个博客或 RSS/Atom 订阅源更新、并对新文章进行过滤与通知的场景,例如跟踪科技媒体、开发者资讯或特定主题博客的最新内容。
限制
资料中未提供关于收费、价格、平台支持范围或效果保证的说明。