Skip to main content

Unofficial Python wrapper for Hacker News API

Project description

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

Example usage:

for story in hn.top_stories(limit=3):
    print hn.get_item(story)

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

API Reference

Class: HackerNews

get_item

Description: Returns Item object

Parameters:

Name

Type

Required

Description

Default

item_id

string/int

Yes

unique item id of Hacker News story, comment etc

None

get_user

Description: Returns User object

Parameters:

Name

Type

Required

Description

Default

user_id

string

Yes

unique user id of a Hacker News user

None

top_stories

Description: Returns list of item ids of current top stories

Parameters:

Name

Type

Required

Description

Default

limit

int

No

specifies the number of stories to be returned

None

get_max_item

Description: Returns current largest item id

Class: Item

From Official HackerNews Item:

Property

Description

item_id

The item’s unique id.

deleted

true if the item is deleted.

item_type

The type of item. One of “job”, “story”, “comment”, “poll”, or “pollopt”.

by

The username of the item’s author.

submission_time

Creation date of the item, in Python datetime.

text

The comment, Ask HN, or poll text. HTML.

dead

true if the item is dead.

parent

The item’s parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll.

kids

The ids of the item’s comments, in ranked display order.

url

The URL of the story.

score

The story’s score, or the votes for a pollopt.

title

The title of the story or poll.

parts

A list of related pollopts, in display order.

raw

original JSON response.

Class: User

From Official HackerNews User:

Property

Description

user_id

The user’s unique username. Case-sensitive.

delay

Delay in minutes between a comment’s creation and its visibility to other users.

created

Creation date of the user, in Python datetime.

karma

The user’s karma.

about

The user’s optional self-description. HTML.

submitted

List of the user’s stories, polls and comments.

raw

original JSON response.

LICENSE

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haxor-0.1.0.tar.gz (6.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page