:newspaper: Unofficial Python API for Hacker News. RESTful API at https://github.com/karan/HNify
Unofficial Python API for Hacker News.
Build Status | Test Coverage | Version | Downloads |
---|---|---|---|
story.get_comments()
)Story.fromid(7024626)
)$ pip install HackerNews
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', limit=60):
print(story.rank, story.title)
HN
get_stories
Parameters:
Name | Type | Required | Description | Default |
---|---|---|---|---|
story_type |
string | No | Returns the stories from this page. One of (empty string) , news2 , newest , best |
(empty string) (top) |
limit |
integer | No | Number of stories required from the given page. Cannot be more than 30. | 30 |
Example:
from hn import HN
hn = HN()
hn.get_stories(story_type='newest', limit=10)
get_leaders
Parameters:
Name | Type | Required | Description | Default |
---|---|---|---|---|
limit |
integer | No | Number of top leaders to return | 10 |
Example:
from hn import HN
hn = HN()
# get top 20 users of HN
hn.get_leaders(limit=20)
Story
Each Story
has the following properties
''
for self posts)''
for self posts)''
for job posts)''
)fromid
Parameters:
Name | Type | Required | Description | Default |
---|---|---|---|---|
item_id |
integer | Yes | Initializes an instance of Story for given item_id. Must be a valid story id. |
Example:
from hn import Story
story = Story.fromid(6374031)
print story.title
get_comments
Parameters:
Name | Type | Required | Description | Default |
---|---|---|---|---|
Example:
from hn import Story
story = Story.fromid(6374031)
comments = story.get_comments()
Comment
Each Comment
has the following properties
User
Each User
has the following properties
See my_test_bot.py
To run the tests locally just do:
$ chmod 777 runtests.sh
$ ./runtests.sh
To run individual tests,
$ python -m unittest tests.<module name>
The tests are run on a local test server with predownloaded original responses.
If HackerNewsAPI has helped you in any way, and you’d like to help the developer, please consider donating.
- BTC: 19dLDL4ax7xRmMiGDAbkizh6WA6Yei2zP5
- Flattr: https://flattr.com/profile/thekarangoel
If you want to add any new features, or improve existing ones, feel free to send a pull request!