kaushikgandhi / HackerNewsAPI

Unofficial Python API for Hacker News.

Home Page:https://github.com/karan/HNify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hacker News API

Unofficial Python API for Hacker News.

Build Status Test Coverage Version Downloads (30 days)
Build Status Coverage Status Latest Version Downloads

Features

  • Compatible with Python 2 (2.7+) and Python 3 (3.3+)
  • Supports 'top', 'newest' and 'best' posts
  • Retrieve comments from posts (flat list for now)
  • Pagination support
  • Handles external posts, self posts and job posts

Installation

$ pip install HackerNews

If Hacker News API has helped you in any way, and you'd like to help the developer, please consider donating.

- BTC: 19dLDL4ax7xRmMiGDAbkizh6WA6Yei2zP5 Link to QR code

- Flattr: https://flattr.com/profile/thekarangoel

Usage

NOTE: Do not make a lot of requests in a short period of time. HN has it's own throttling system.

from hn import HN

hn = HN()

# print the first 2 pages of newest stories
for story in hn.get_stories(story_type='newest', page_limit=2):
    print story.rank, story.title

Each Story has the following properties

  • rank - the rank of story on the page (keep pagination in mind)
  • story_id - the story's id
  • title - the title of the story
  • is_self - true for self/job stories
  • link - the url it points to ('' for self posts)
  • domain - the domain of the link ('' for self posts)
  • points - the points/karma on the story
  • submitter - the user who submitted the story ('' for job posts)
  • submitter_profile - the above user's profile link (can be '')
  • published_time - the published time
  • num_comments - the number of comments a story has
  • comments_link - the link to the comments page

Example

See my_test_bot.py

Contribute

If you want to add any new features, or improve existing ones, feel free to send a pull request!

Tests

To run the tests locally just install the requirements by running pip install -r requirements.txt.

Then run the command nosetests -v in the command line from within the projects root directory.

Bitdeli Badge

About

Unofficial Python API for Hacker News.

https://github.com/karan/HNify

License:MIT License