SKILL.md
唯讀
名稱
hackernews
描述
Hacker News API,用於取得文章和留言。當使用者提到「Hacker News」、「HN」、「Y Combinator」或詢問科技新聞時使用。
使用方式
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 |
文章網址(若有外部連結) |
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 或缺失(例如 Ask HN 的
url) - Unix 時間戳記:所有時間均為 Unix 時間戳記,請依需求轉換






