Create a client and fetch data from Hacker News.
Fetch a story
from hnx import HackerNews
async def main():
async with HackerNews() as hn:
story = await hn.item(44321234)
print(story.title)
print(story.score)
Get top stories
async with HackerNews() as hn:
ids = await hn.top()
print(ids[:10])
Fetch multiple items
async with HackerNews() as hn:
items = await hn.items(
[44321234, 44321198, 44321077]
)
for item in items:
print(item.id)
Fetch a user
async with HackerNews() as hn:
user = await hn.user("pg")
print(user.karma)
Fetch a complete thread
async with HackerNews() as hn:
thread = await hn.thread(44321234)
print(thread.root.title)
print(thread.comment_count)