Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hacker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hacker

Unofficial Python wrapper for Hacker News API

  • 0.3.1
  • PyPI
  • Socket score

Maintainers
1

#haxor

travis coverall version supported license

Unofficial Python wrapper for official Hacker News API.

Installation

pip install haxor

Usage

import and initialization:

from hackernews import HackerNews
hn = HackerNews()

Get certain user info by user id (i.e. username on Hacker News)

user = hn.get_user('pg')
# >>> user.user_id
# pg
# >>> user.karma
# 155040

Stories, comments, jobs, Ask HNs and even polls are just items and they have unique item id. To get info of an item by item id:

item = hn.get_item(8863)
# >>> item.title
# "My YC app: Dropbox - Throw away your USB drive"
# >>> item.type
# story
# >>> item.kids
# [ 8952, 9224, 8917, ...]

To get item ids of current top stories:

top_story_ids = hn.top_stories()
# >>> top_story_ids
# [8432709, 8432616, 8433237, ...]

To get current largest item id:

max_item = hn.get_max_item()
# >>> max_item
# 8433746

Examples

Get top 10 stories:

for story_id in hn.top_stories(limit=10):
    print hn.get_item(story_id)

# <hackernews.Item: 8432709 - Redis cluster, no longer vaporware>
# <hackernews.Item: 8432423 - Fluid Actuators from Disney Research Make Soft, Safe Robot Arms>
# <hackernews.Item: 8433237 - Is Capturing Carbon from the Air Practical?>
# ...
# ...

Find all the 'jobs' post from Top Stories:

for story_id in hn.top_stories():
    story = hn.get_item(story_id)
    if story.item_type == 'job':
        print story

# <hackernews.Item: 8437631 - Lever (YC S12) hiring JavaScript experts, realtime systems engineers, to scale DerbyJS>
# <hackernews.Item: 8437036 - Product Designer (employee #1) to Organize the World's Code – Blockspring (YC S14)>
# <hackernews.Item: 8436584 - Django and iOS Hackers Needed – fix healthcare with Drchrono>
# ...
# ...

Find Python jobs from monthly who is hiring thread:

# Who is hiring
# https://news.ycombinator.com/item?id=8394339

who_is_hiring = hn.get_item(8394339)

for comment_id in who_is_hiring.kids:
    comment = hn.get_item(comment_id)
    if 'python' in comment.text.lower():
        print comment.item_id

# 8395568
# 8394964
# ...
# ...

API Reference

Class: HackerNews

Parameters:

NameTypeRequiredDescriptionDefault
versionstringNospecifies Hacker News API versionv0

get_item

Description: Returns Item object

Parameters:

NameTypeRequiredDescriptionDefault
item_idstring/intYesunique item id of Hacker News story, comment etcNone

get_user

Description: Returns User object

Parameters:

NameTypeRequiredDescriptionDefault
user_idstringYesunique user id of a Hacker News userNone

top_stories

Description: Returns list of item ids of current top stories

Parameters:

NameTypeRequiredDescriptionDefault
limitintNospecifies the number of stories to be returnedNone

new_stories

Description: Returns list of item ids of current new stories

Parameters:

NameTypeRequiredDescriptionDefault
limitintNospecifies the number of stories to be returnedNone

ask_stories

Description: Returns list of item ids of latest Ask HN stories

Parameters:

NameTypeRequiredDescriptionDefault
limitintNospecifies the number of stories to be returnedNone

show_stories

Description: Returns list of item ids of latest Show HN stories

Parameters:

NameTypeRequiredDescriptionDefault
limitintNospecifies the number of stories to be returnedNone

job_stories

Description: Returns list of item ids of latest Job stories

Parameters:

NameTypeRequiredDescriptionDefault
limitintNospecifies the number of stories to be returnedNone

updates

Description: Returns list of item ids and user ids that have been changed/updated recently.

get_max_item

Description: Returns current largest item id

Class: Item

From Official HackerNews Item:

PropertyDescription
item_idThe item’s unique id.
deletedtrue if the item is deleted.
item_typeThe type of item. One of “job”, “story”, “comment”, “poll”, or “pollopt”.
byThe username of the item’s author.
submission_timeCreation date of the item, in Python datetime.
textThe comment, Ask HN, or poll text. HTML.
deadtrue if the item is dead.
parentThe item’s parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll.
kidsThe ids of the item’s comments, in ranked display order.
urlThe URL of the story.
scoreThe story’s score, or the votes for a pollopt.
titleThe title of the story or poll.
partsA list of related pollopts, in display order.
raworiginal JSON response.

Class: User

From Official HackerNews User:

PropertyDescription
user_idThe user’s unique username. Case-sensitive.
delayDelay in minutes between a comment’s creation and its visibility to other users.
createdCreation date of the user, in Python datetime.
karmaThe user’s karma.
aboutThe user’s optional self-description. HTML.
submittedList of the user’s stories, polls and comments.
raworiginal JSON response.

Development

For local development do pip installation of requirements-dev.txt:

pip install -r requirements-dev.txt

LICENSE

The mighty MIT license. Please check LICENSE for more details.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc