MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / hackernews_top_stories

Function hackernews_top_stories

web_programming/get_top_hn_posts.py:18–24  ·  view source on GitHub ↗

Get the top max_stories posts from HackerNews - https://news.ycombinator.com/

(max_stories: int = 10)

Source from the content-addressed store, hash-verified

16
17
18def hackernews_top_stories(max_stories: int = 10) -> list[dict]:
19 """
20 Get the top max_stories posts from HackerNews - https://news.ycombinator.com/
21 """
22 url = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
23 story_ids = httpx.get(url, timeout=10).json()[:max_stories]
24 return [get_hackernews_story(story_id) for story_id in story_ids]
25
26
27def hackernews_top_stories_as_markdown(max_stories: int = 10) -> str:

Callers 1

Calls 3

get_hackernews_storyFunction · 0.85
jsonMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected