RSS工具的使用
安装过程 (注意事先安装好 npm!):
git clone https://github.com/DIYgod/RSSHub.git
cd RSSHub && npm install
npm install puppeteer
npm run build && npm run start
这样就打开了 web 服务了!
但是, 距离可以接受公众号服务还早!
先去 https://github.com/DIYgod/RSSHub-Radar/releases/tag/v2.1.0 下载 Radar (按照你用的浏览器下载):
然后如果想要一个自动获取 RSS 的脚本, 可以参考下面的, 然后加到系统的 crontab 或者自行配置自动化即可.
import requests
import feedparser
import datetime
import os
feeds = {
"LLVM Commits": "https://github.com/llvm/llvm-project/commits/main.atom",
"Clang Commits": "https://github.com/llvm/clang/commits/main.atom",
"MLIR Commits": "https://github.com/llvm/llvm-project/commits/main.atom", # MLIR 目前还在llvm-project里
"GCC Commits (mirror)": "https://github.com/gcc-mirror/gcc/commits/master.atom",
}
save_dir = "../hexo/source/_posts/⑩理论/RSS/"
today = datetime.datetime.now().strftime("%Y%m%d")
filename = os.path.join(save_dir, f"{today}.md")
header = f"""---
title: {today}
categories:
- 理论
- RSStags: date: {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
cover: description: RSS
swiper_index:
---
"""
def fetch_and_save():
contents = []
headers = {'User-Agent': 'Mozilla/5.0'}
for name, url in feeds.items():
print(f"🔗 正在拉取: {name}")
try:
response = requests.get(url, headers=headers, timeout=10)
print(f"📥 HTTP 状态码: {response.status_code}")
if response.status_code != 200:
print(f"❌ 无法获取 {name},状态码: {response.status_code}")
continue
feed = feedparser.parse(response.content)
print(f"📄 解析到 {len(feed.entries)} 条条目")
if feed.entries:
for entry in feed.entries[:10]: # 每个源最多取 10 条
title = entry.title if hasattr(entry, 'title') else "无标题"
link = entry.link if hasattr(entry, 'link') else "#"
published = entry.published if hasattr(entry, 'published') else "无发布日期"
contents.append(f"- [{title}]({link}) 发布于 {published}")
else:
print(f"⚠️ {name} 暂时没有内容。")
except Exception as e:
print(f"❌ 拉取 {name} 时出错: {e}")
if contents:
os.makedirs(save_dir, exist_ok=True)
with open(filename, "w", encoding="utf-8") as f:
f.write(header + "\n\n")
f.write("\n".join(contents))
print(f"✅ 成功写入: {filename}")
else:
print("⚠️ 所有源都无内容,今天跳过。")
if __name__ == "__main__":
fetch_and_save()
评论