tool.py
1 """Hacker News Tool Example. 2 3 This example demonstrates how to use the Hacker News tool with PraisonAI agents. 4 5 Requirements: 6 pip install "praisonai[tools]" 7 8 Usage: 9 python tool.py 10 11 Note: No API key required! 12 """ 13 14 from praisonai_tools import HackerNewsTool 15 16 17 def main(): 18 # Initialize Hacker News tool 19 hn = HackerNewsTool() 20 21 # Example 1: Get top stories 22 print("=" * 60) 23 print("Example 1: Top Stories") 24 print("=" * 60) 25 26 stories = hn.get_top_stories(limit=5) 27 28 if stories and "error" in stories[0]: 29 print(f"Error: {stories[0]['error']}") 30 else: 31 print(f"Found {len(stories)} top stories:") 32 for story in stories: 33 print(f" - {story.get('title', 'N/A')[:50]}...") 34 print(f" Score: {story.get('score', 'N/A')} | Comments: {story.get('descendants', 'N/A')}") 35 print(f" URL: {story.get('url', 'N/A')[:60]}...") 36 print() 37 38 print("✅ Hacker News tool working correctly!") 39 40 41 if __name__ == "__main__": 42 main()