Install
openclaw skills install @zrisingz-crypto/practical-news-monitor支持地缘政治、石油、黄金等关键词的多数据源新闻监控,自动保存数据并生成摘要报告,易于扩展和定制。
openclaw skills install @zrisingz-crypto/practical-news-monitor专注于可工作的数据源和易扩展性,支持地缘政治、石油、黄金等关键词监控。
pip3 install requests
cd /path/to/skill
python3 practical_news_monitor.py monitor
python3 practical_news_monitor.py test
在脚本中编辑 MONITOR_KEYWORDS 字典:
MONITOR_KEYWORDS = {
'geopolitical': ['中东', '伊朗', '以色列', '巴勒斯坦'],
'oil': ['石油', '原油', '油价', 'OPEC'],
'gold': ['黄金', '贵金属', '避险', '金价'],
'sanctions': ['制裁', '禁令', '限制', '封锁'],
'shipping': ['航运', '海运', '物流', '苏伊士'],
'conflict': ['冲突', '战争', '打击', '攻击']
}
在 _init_sources() 方法中添加新的数据源配置:
source_configs = [
{
'type': 'json_api',
'name': '我的JSON API',
'config': {
'enabled': True,
'url': 'https://api.example.com/news',
'data_path': 'data.items',
'title_field': 'title',
'url_field': 'link',
'time_field': 'published_at',
'timeout': 15,
'limit': 20
}
},
{
'type': 'html_parse',
'name': '我的HTML网站',
'config': {
'enabled': True,
'url': 'https://example.com/news',
'parse_rules': {
'container_selector': r'<div class="news-item">(.*?)</div>',
'title_selector': r'<a[^>]*>([^<]+)</a>',
'link_selector': r'href="([^"]+)"'
},
'timeout': 15,
'limit': 20
}
}
]
默认数据保存位置:
/Users/zenozhou/shared_memory/practical_news/
可以在脚本中修改 DATA_DIR 变量来更改位置。
监控运行后会生成:
============================================================
📊 实用新闻监控
============================================================
监控时间: 2026-03-23 08:30:00
📡 正在获取 新浪财经(示例)...
✓ 获取到 20 条新闻
📡 正在获取 东方财富(示例)...
✓ 获取到 15 条新闻
✅ 共获取 35 条新闻
📈 相关新闻: 8 条
📊 来源统计:
新浪财经(示例): 5/20 相关
东方财富(示例): 3/15 相关
💾 数据已保存: /Users/zenozhou/shared_memory/practical_news/monitor_2026-03-23_083000.json
继承 NewsDataSource 基类并实现 fetch() 方法:
class MyCustomSource(NewsDataSource):
"""我的自定义数据源"""
def fetch(self) -> List[Dict[str, Any]]:
"""获取新闻数据"""
# 实现你的数据获取逻辑
pass
重写 check_relevance() 方法:
def check_relevance(self, title: str, keywords: Dict[str, List[str]]) -> Dict[str, Any]:
"""自定义相关性检查逻辑"""
# 实现你的相关性检查
pass
A: 在 MONITOR_KEYWORDS 字典中添加新的键值对即可。
A: 检查 URL 是否正确,是否需要 headers 或 cookies,尝试在浏览器中访问确认。
A: 使用 cron 或其他调度工具定期运行脚本。
MIT License
欢迎提交 Issue 和 Pull Request!
由 Zbot 自动生成 💥