前言 在日常工作和学习中,我们往往需要关注各大平台的热点资讯。手动浏览多个平台既费时又容易遗漏重要信息。本文将介绍如何使用 OpenClaw 部署 DailyHot 热榜服务,实现全网热点的自动化获取,并配置定时任务实现:
每天早上8点 - 自动推送全网热点新闻
每天上午10点 - 获取AI资讯并自动生成博客文章
项目介绍 DailyHot 是什么? DailyHotApi 是一个聚合热门数据的 API 接口项目,支持 56个平台 的热榜数据获取,包括:
社交媒体 : 微博、知乎、贴吧、V2EX、NGA、虎扑
视频直播 : B站、抖音、快手、AcFun、酷安
新闻资讯 : 百度、澎湃新闻、36氪、腾讯新闻、网易新闻
科技社区 : IT之家、少数派、掘金、CSDN
游戏 : 原神、米游社、崩坏、英雄联盟
其他 : 历史上的今天、气象预警、地震速报
OpenClaw 是什么? OpenClaw 是一个 AI 助手平台,支持通过 Skill(技能)扩展功能。通过配置定时任务,可以实现自动化的信息处理和任务执行。
部署过程 1. 环境准备 首先确保系统已安装:
docker --version python3 --version pip3 --version
2. 配置 Docker 镜像源 由于国内网络环境,Docker 官方源可能无法访问,需要配置国内镜像:
sudo tee /etc/docker/daemon.json << 'EOF' { "registry-mirrors" : [ "https://docker.1panel.live" , "https://hub.rat.dev" , "https://docker.m.daocloud.io" ] } EOFsudo systemctl daemon-reloadsudo systemctl restart docker
3. 部署 DailyHotApi 服务 docker pull imsyy/dailyhot-api:latest docker run -d \ --name dailyhotapi \ -p 6688:6688 \ --restart unless-stopped \ imsyy/dailyhot-api:latest curl http://localhost:6688/all
4. 安装 Python 依赖 cd ~/openclaw-daily-hot-news pip3 install -r requirements.txt --break-system-packages python3 -m venv venvsource venv/bin/activate pip install -r requirements.txt
5. 配置环境变量 创建 .env 文件:
cat > .env << 'EOF' DAILY_HOT_API_URL=http://localhost:6688 DAILY_HOT_MAX_ITEMS=20 DAILY_HOT_TIMEOUT=10 DAILY_HOT_DATA_DIR=/home/wenjun/openclaw-daily-hot-news/data DAILY_HOT_AUTO_SAVE=true FEISHU_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx EOF
遇到的问题及解决方案 问题1: Docker 镜像拉取失败 现象 :
Error response from daemon: failed to resolve reference "docker.io/imsyy/dailyhot-api:latest": dial tcp [2a03:2880:f107:83:face:b00c:0:25de]:443: i/o timeout
解决 : 配置国内 Docker 镜像源,使用 docker.1panel.live 或 hub.rat.dev 镜像。
问题2: Python 相对导入错误 现象 :
ImportError: attempted relative import with no known parent package
解决 : 创建独立的 CLI 入口脚本 cli.py,使用绝对导入,并在运行时加载环境变量:
env_file = Path(__file__).parent / '.env' if env_file.exists(): with open (env_file) as f: for line in f: if line.strip() and '=' in line: key, value = line.split('=' , 1 ) os.environ[key] = valuefrom api_client import api_client
问题3: 权限错误 现象 :
PermissionError: [Errno 13 ] Permission denied: '/ root/ .openclaw'
解决 : 修改 config.py,将默认数据目录改为当前工作目录:
self .data_dir = os.getenv("DAILY_HOT_DATA_DIR" , "/root/.openclaw/..." ) default_data_dir = os.path.join(os.getcwd(), "data" )self .data_dir = os.getenv("DAILY_HOT_DATA_DIR" , default_data_dir)
定时任务配置 1. 创建定时任务脚本 创建 cron_jobs.py,实现两个核心功能:
功能一:热点新闻推送 async def fetch_hot_news (): """获取热点新闻(跨平台聚合)""" platforms = [ ('weibo' , '微博' ), ('zhihu' , '知乎' ), ('bilibili' , 'B站' ), ('36kr' , '36氪' ), ('baidu' , '百度' ), ] all_hot = [] for source_id, name in platforms: result = await api_client.fetch_hot_list(source_id) if result and result.get('data' ): for item in result.get('data' , [])[:3 ]: all_hot.append({ 'title' : item.get('title' , '' ), 'platform' : name, 'hot' : item.get('hot' , '' ), }) all_hot.sort(key=lambda x: parse_hot_num(x['hot' ]), reverse=True ) return all_hot[:15 ]
功能二:AI 资讯博客生成 async def fetch_ai_news (): """获取AI相关资讯""" ai_platforms = [ ('36kr' , '36氪' ), ('ithome' , 'IT之家' ), ('juejin' , '稀土掘金' ), ] ai_keywords = ['AI' , '人工智能' , 'ChatGPT' , '大模型' , 'LLM' , 'OpenAI' , 'Claude' ] ai_news = [] for source_id, name in ai_platforms: result = await api_client.fetch_hot_list(source_id) for item in result.get('data' , []): title = item.get('title' , '' ) if any (kw in title for kw in ai_keywords): ai_news.append(item) return ai_news[:10 ]
2. 配置 OpenClaw 定时任务 创建 setup_cron.py 脚本:
jobs = { "version" : 1 , "jobs" : [ { "id" : "daily_hot_news_morning" , "name" : "每日热点新闻推送" , "schedule" : "0 8 * * *" , "command" : "python3 cron_jobs.py morning_hot_news" , "enabled" : True }, { "id" : "daily_ai_blog" , "name" : "每日AI资讯博客生成" , "schedule" : "0 10 * * *" , "command" : "python3 cron_jobs.py generate_ai_blog" , "enabled" : True } ] }
3. 飞书通知集成 async def send_feishu_notification (title, content ): """发送飞书通知""" if not FEISHU_WEBHOOK: return False message = { "msg_type" : "post" , "content" : { "post" : { "zh_cn" : { "title" : title, "content" : [[{"tag" : "text" , "text" : content}]] } } } } resp = requests.post(FEISHU_WEBHOOK, json=message, timeout=30 ) return resp.json().get('code' ) == 0
使用效果 热点新闻推送示例 每天早上8点,飞书群会收到如下消息:
🔥 2026 年03 月04 日 热点新闻 Top15 📅 2026 年03 月04 日 全网热点 TOP15 1 . [知乎] 不少省份提出推进「好房子、好小区」建设... [4340000] 2 . [知乎] 2026 年全国两会,你最关心哪些话题?... [3920000] 3 . [B站] 《崩坏:星穹铁道》火花角色PV ... [22211] ... 💡 数据来源: 微博、知乎、B 站、36 氪、百度
自动生成的博客文章 每天早上10点,会自动在博客目录生成 Markdown 文章:
--- title: "AI资讯速递 - 2026年03月04日" date: 2026-03-04 10:00:00 categories: AI资讯tags: [AI, 人工智能, 每日速递, 自动生成] --- ## 今日AI热点 (2026-03-04) ### 1. Claude全球宕机,机房爆炸... [查看原文 ](https://www.36kr.com/p/xxxx )*来源: 36氪* ---*本文由 OpenClaw DailyHot Skill 自动生成*
技术架构图 ┌─────────────────────────────────────────────────────────────┐ │ 定时任务层 │ │ ┌─────────────────┐ ┌─────────────────────┐ │ │ │ 早上8 :00 │ │ 上午10 :00 │ │ │ │ 热点新闻推送 │ │ AI资讯博客生成 │ │ │ └────────┬────────┘ └──────────┬──────────┘ │ └───────────┼────────────────────────────────────┼──────────────┘ │ │ ▼ ▼ ┌─────────────────────────────────────────────────────────────┐ │ DailyHot Skill 层 │ │ (Python + OpenClaw) │ └─────────────────────────────────────────────────────────────┘ │ │ ▼ ▼ ┌────────────────────────────┐ ┌──────────────────────┐ │ DailyHotApi 服务 │ │ 博客发布助手 │ │ (Docker: dailyhotapi) │ │ (blog-publisher) │ │ Port: 6688 │ │ │ └────────────────────────────┘ └──────────────────────┘ │ │ ▼ ▼ ┌────────────────────────────┐ ┌──────────────────────┐ │ 56 个平台热榜数据 │ │ Hexo 博客站点 │ │ - 微博、知乎、B站 │ │ + 封面图生成 │ │ - 36 氪、IT之家等 │ │ + OSS 上传 │ └────────────────────────────┘ └──────────────────────┘
总结 通过 OpenClaw + DailyHot + Docker 的组合,我们实现了一个完整的信息自动化工作流:
信息聚合 : 一站式获取56个平台的热点数据
智能筛选 : 基于关键词自动筛选AI相关资讯
自动发布 : 定时生成博客文章并配图
即时通知 : 通过飞书机器人实时推送热点
这套系统不仅提高了信息获取效率,还能将优质内容自动沉淀到博客,形成知识积累。后续可以考虑接入更多数据源,或者使用 LLM 对热点进行智能分析和总结。
参考链接
本文中提到的技术栈:Docker、Python 3.12、OpenClaw、aiohttp、requests
文章作者: 阿文
版权声明: 本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0 许可协议。转载请注明来自
阿文的博客 !
评论
0 条评论