Skip to main content

Overview

Hacker News tool allows you to fetch top stories, new stories, and comments from Hacker News. No API key required.

Installation

pip install "praisonai[tools]"
No API key required!

Quick Start

from praisonai_tools import HackerNewsTool

# Initialize
hn = HackerNewsTool()

# Get top stories
stories = hn.get_top_stories(limit=5)
print(stories)

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import HackerNewsTool

agent = Agent(
    name="TechNews",
    instructions="You are a tech news assistant. Use Hacker News to find trending stories.",
    tools=[HackerNewsTool()]
)

response = agent.chat("What are the top stories on Hacker News today?")
print(response)

Available Methods

get_top_stories(limit=10)

Get top stories from Hacker News.
from praisonai_tools import HackerNewsTool

hn = HackerNewsTool()
stories = hn.get_top_stories(limit=5)

# Returns:
# [
#     {"title": "...", "url": "...", "score": 150, "comments": 45},
#     ...
# ]

get_new_stories(limit=10)

Get newest stories.
stories = hn.get_new_stories(limit=5)

get_best_stories(limit=10)

Get best stories.
stories = hn.get_best_stories(limit=5)

get_story(story_id)

Get a specific story by ID.
story = hn.get_story(12345678)

Function-Based Usage

from praisonai_tools import get_hackernews_top

# Quick access without instantiating class
stories = get_hackernews_top(limit=5)

CLI Usage

# Use with praisonai
praisonai --tools HackerNewsTool "What are the trending tech stories today?"

Error Handling

from praisonai_tools import HackerNewsTool

hn = HackerNewsTool()
stories = hn.get_top_stories(limit=5)

if stories and "error" in stories[0]:
    print(f"Error: {stories[0]['error']}")
else:
    for story in stories:
        print(f"- {story['title']} ({story['score']} points)")

Common Errors

ErrorCauseSolution
requests not installedMissing dependencyRun pip install requests
Connection errorNetwork issueCheck internet connection
Rate limitedToo many requestsAdd delay between requests