关于 hackernews
hackernews 是通过 Firebase API 获取 Hacker News 故事、评论、职位和用户数据的技能,提供端点示例及命令行查询和筛选方法。
主要功能
- 01获取热门、最佳和最新故事
- 02获取 Ask HN、Show HN 和职位
- 03读取条目与评论详情
- 04查询用户资料和投稿
- 05查看近期变更的条目和资料
适用场景
- 01浏览 Hacker News 最新故事
- 02查看故事得分和评论
- 03查找用户近期投稿
- 04轮询最近变更的内容
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ okou-ai/ okou-skills --skill hackernews安装后在 Claude Code 中输入/hackernews确认已加载。
详细介绍
使用方法
1. 获取热门故事
获取当前排名前 500 的故事 ID:
curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq '.[:10]'
2. 获取最佳故事
获取最佳故事(长期获得最多投票的故事):
curl -s "https://hacker-news.firebaseio.com/v0/beststories.json" | jq '.[:10]'
3. 获取最新故事
获取最新的故事:
curl -s "https://hacker-news.firebaseio.com/v0/newstories.json" | jq '.[:10]'
4. 获取 Ask HN 故事
获取“Ask HN”帖子:
curl -s "https://hacker-news.firebaseio.com/v0/askstories.json" | jq '.[:10]'
5. 获取 Show HN 故事
获取“Show HN”帖子:
curl -s "https://hacker-news.firebaseio.com/v0/showstories.json" | jq '.[:10]'
6. 获取招聘故事
获取招聘信息:
curl -s "https://hacker-news.firebaseio.com/v0/jobstories.json" | jq '.[:10]'
条目详情
7. 获取故事/评论/招聘信息详情
根据 ID 获取任意条目的完整详情。将 <item-id> 替换为实际条目 ID:
curl -s "https://hacker-news.firebaseio.com/v0/item/<item-id>.json"
响应字段:
| 字段 | 描述 |
|---|---|
id | 唯一条目 ID |
type | story、comment、job、poll、pollopt |
by | 作者用户名 |
time | Unix 时间戳 |
title | 故事标题(仅限故事) |
url | 故事 URL(如果是外部链接) |
text | 内容文本(Ask HN、评论) |
score | 获赞数 |
descendants | 评论总数 |
kids | 子评论 ID 数组 |
8. 获取带详情的多个故事
获取排名前 5 的故事及其完整详情。将 <item-id> 替换为实际条目 ID:
curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq '.[:5][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq '{id, title, score, url, by}'
done
9. 获取带评论的故事
获取一个故事及其顶层评论。将 <story-id> 替换为实际故事 ID:
curl -s "https://hacker-news.firebaseio.com/v0/item/<story-id>.json" | jq '{title, score, descendants, kids}'
然后,对于 kids 数组中的每个评论 ID,将 <comment-id> 替换为实际评论 ID:
curl -s "https://hacker-news.firebaseio.com/v0/item/<comment-id>.json" | jq '{by, text, score}'
用户数据
10. 获取用户资料
获取用户详情。将 <username> 替换为实际用户名:
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json"
响应字段:
| 字段 | 描述 |
|---|---|
id | 用户名 |
created | 账户创建时间戳 |
karma | 用户的 karma 分数 |
about | 用户简介(HTML) |
submitted | 已提交条目 ID 数组 |
11. 获取用户最近提交的内容
获取用户最近提交的内容。将 <username> 替换为实际用户名:
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json" | jq '.submitted[:5]'
实时更新
12. 获取最大条目 ID
获取当前最大的条目 ID(可用于轮询新条目):
curl -s "https://hacker-news.firebaseio.com/v0/maxitem.json"
13. 获取已更改的条目和资料
获取最近更改的条目和资料(用于实时更新):
curl -s "https://hacker-news.firebaseio.com/v0/updates.json"
实用示例
获取今日排名前 10 的故事及其分数
curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq '.[:10][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r '"\(.score) points | \(.title) | \(.url // "Ask HN")"'
done
查找高分故事(100 分以上)
curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq '.[:30][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.score >= 100) | "\(.score) | \(.title)"'
done
获取最新的 AI/ML 相关故事
curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq '.[:50][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.title | test("AI|GPT|LLM|Machine Learning|Neural"; "i")) | "\(.score) | \(.title)"'
done
API 端点摘要
| 端点 | 描述 |
|---|---|
/v0/topstories.json | 排名前 500 的故事 |
/v0/beststories.json | 最佳故事 |
/v0/newstories.json | 最新的 500 个故事 |
/v0/askstories.json | Ask HN 故事 |
/v0/showstories.json | Show HN 故事 |
/v0/jobstories.json | 招聘信息 |
/v0/item/{id}.json | 条目详情 |
/v0/user/{id}.json | 用户资料 |
/v0/maxitem.json | 当前最大条目 ID |
/v0/updates.json | 已更改的条目/资料 |
指南
- 未说明速率限制:但请合理使用,批量获取时添加延迟
- 使用 jq 进行筛选:筛选 JSON 响应以提取所需数据
- 缓存结果:故事不会频繁变化,尽可能缓存
- 谨慎批量请求:每个条目都需要单独调用 API
- 处理 null 值:某些字段可能为 null 或缺失(例如,Ask HN 的
url) - Unix 时间戳:所有时间均为 Unix 时间戳,请按需转换
评论
支持 Markdown