Skip to content

hellodk34/ithome_push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IT之家 RSS 新闻监控 + ntfy.sh 推送

监控 IT之家 RSS 新闻,匹配关键词后通过 ntfy.sh 推送到手机通知栏。

快速开始

python3 -m venv .venv
.venv/bin/pip install -r requirements.txt

编辑 config.py,将 NTFY_TOPIC 改为你在 ntfy App 中订阅的主题名,然后运行:

.venv/bin/python monitor.py

配置

编辑 config.py

RSS_URL = "https://www.ithome.com/rss/"
NTFY_SERVER = "https://ntfy.sh 或者任何 ntfy 私有实例的服务端地址"
NTFY_TOPIC = "你的 ntfy 主题"              # 改为你自己的主题

KEYWORDS = [
    r"微信\s*Linux",                        # 匹配"微信Linux"、"微信 Linux"等
    r"微信\s*Native",
    # 在此添加更多关键词(正则表达式)
]

关键词使用正则匹配,\s* 可匹配中英文之间的任意空白。

部署方式

方式一:直接运行(crontab)

每 10 分钟执行一次,避免请求频率过高:

crontab -e

添加:

*/10 * * * * cd /path/to/ithome_push && .venv/bin/python monitor.py >> monitor.log 2>&1

方式二:Docker(推荐)

构建镜像:

docker build -t ithome_push .

启动容器:

初始化持久化文件(首次运行需显式创建,确保 Docker 挂载为正常文件):

echo '{}' > sent.json

启动容器:

docker run -itd \
  --name ithome_push \
  --restart always \
  -e TZ=Asia/Shanghai \
  -v "$(pwd)/config.py":/app/config.py \
  -v "$(pwd)/sent.json":/app/sent.json \
  ithome_push

使用 "$(pwd)" 自动取当前目录的绝对路径,确保在项目目录下执行即可。

参数说明:

参数 作用
-e TZ=Asia/Shanghai 日志时间设置为北京时间
-v config.py 挂载配置文件,修改后只需重启容器,无需重新构建
-v sent.json 持久化已推送记录,容器重建后不会重复推送

查看日志:

docker logs ithome_push

重启容器(修改配置后):

docker restart ithome_push

手动触发

重启容器即可立即执行一次检查:

docker restart ithome_push

ntfy.sh 设置

  1. 手机安装 ntfy App
  2. 在 App 中订阅你设置的主题名称
  3. 运行脚本后,匹配到关键词时手机即可收到推送通知,点击直接打开文章

去重

已推送的文章以 {URL: 标题} 格式保存在 sent.json 中,不会重复推送(最多保留最近 10000 条)。

依赖

  • feedparser — RSS 解析
  • requests — HTTP 请求

About

监控 IT之家 RSS 新闻,匹配关键词后通过 ntfy.sh 推送到手机通知栏

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors