• Stars
    star
    390
  • Rank 110,242 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created about 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“° Unofficial Python API for Hacker News. RESTful API at https://github.com/karan/HNify

Hacker News API

Unofficial Python API for Hacker News.

Build Status Test Coverage Version Downloads
Build Status Coverage Status Latest Version Downloads

Features

  • Compatible with Python 2 (2.7+).
  • Supports 'top', 'news2','newest' and 'best' posts
  • Retrieve comments from posts (flat list for now) (story.get_comments())
  • Pagination support for comments
  • Handles external posts, self posts and job posts
  • Get post details for any post (Story.fromid(7024626))

Installation

$ pip install HackerNews

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', limit=60):
    print(story.rank, story.title)

API Reference

Class: HN

Get stories from Hacker News

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)

Class: Story

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

Make an object from the ID of a story

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 a list of Comment's for this story

get_comments

Parameters:

Name Type Required Description Default

Example:

from hn import Story
story = Story.fromid(6374031)
comments = story.get_comments()

Class: Comment

Each Comment has the following properties

  • comment_id - the comment's item id
  • level - comment's nesting level
  • user - user's name who submitted the post
  • time_ago - time when it was submitted
  • body - text representation of comment (unformatted)
  • body_html - html of comment, may not be valid

Class: User

Each User has the following properties

  • username - user's profile name
  • date_created - when the profile was created
  • karma - user's e-points
  • avg - user's average karma per day

Examples

See my_test_bot.py

Tests

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.

Donations

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

Contribute

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

More Repositories

1

Projects

πŸ“ƒ A list of practical projects that anyone can solve in any programming language.
44,914
star
2

Projects-Solutions

πŸ“Ÿ Links to others' solutions to Projects (https://github.com/karan/Projects/)
4,117
star
3

joe

πŸƒ A .gitignore magician in your command line
Go
2,877
star
4

slack-overflow

A programmer's best friend, now in Slack.
Python
813
star
5

TPB

☁️ Python API for ThePirateBay.
HTML
331
star
6

slack-news

Read news from multiple sources within Slack by just typing /news.
JavaScript
123
star
7

chrome-url-alias

Chrome extension to set URL aliases ("m/" goes to "mail.google.com" etc)
JavaScript
112
star
8

Swift-Algorithms

Implementation of various algorithms and data structures in Swift.
Swift
110
star
9

Hook

ProductHunt REST API (Unofficial) - DISCONTINUED
JavaScript
91
star
10

HNify

Hacker News REST API using Flask on Heroku using memcached.
Python
91
star
11

fleets

Automatically delete tweets, retweets, and favorites.
Go
89
star
12

SoundWall

A faster, more pleasant way to discover new music.
JavaScript
77
star
13

atom-terminal

Atom package to open terminal on current file's directory with "ctrl-shift-t"
CoffeeScript
70
star
14

validator.dart

🐒 String validation and sanitization for Dart.
Dart
64
star
15

vocabulary

Golang package to get meanings, synonyms, antonyms and more for a word
Go
60
star
16

slashgif

Post GIFs to Twitter by doing "@slashgif coffee break"
Python
55
star
17

Spear

Product Hunt for Hackers - a CLI to Product Hunt.
Python
53
star
18

scInstant

SoundCloud Instant Search
JavaScript
51
star
19

x-meme

The meme element for modern web
48
star
20

RedditAgain

Migrate an old Reddit account to a new one.
Python
45
star
21

slackzon

Simple Amazon Product Search in Slack
Python
39
star
22

Qnowledge

Knowledge API for Quora. (Code removed)
Python
39
star
23

dotfiles

~/* - all my dotfiles with bootstrapping script. 10X productivity gains. ❀️
Shell
39
star
24

slack-hn

SEE https://github.com/karan/slack-news INSTEAD
JavaScript
36
star
25

nojs.club

You don't need Javascript to make a beautiful, usable web. How it works: https://goel.io/nojs-club
SCSS
34
star
26

libfib

An experiment to run Go code directly from Python.
Python
29
star
27

brain2music

🎡 EEG brainwave data to music (more like noise) in realtime.
JavaScript
29
star
28

todo-swift

Very simple iOS todo list app built with Swift
Swift
26
star
29

s

🌡 A high-performance, anonymous URL shortener built using Redis + Node.js with a API-backed design.
JavaScript
23
star
30

NobodyDoesThis

Reddit bot that scans 3 day-old /r/DoesAnybodyElse posts with 0 score and then comments "Nope, it's just you."
Python
22
star
31

PebBus

⏰ Pebble app for OneBusAway.
JavaScript
21
star
32

language.dart

🌺 Natural language processing utilities for Dart
Dart
20
star
33

Storming

β˜” Hacking The Tweetstorm... With Pictures of Text
CSS
16
star
34

What-Would-I-Tweet

Automatically generates tweets for you! It trains a Markov bot based on bigram probabilities derived from your tweet history.
CSS
14
star
35

slashRemindMe

A Twitter bot to remember things or threads. [INACTIVE]
Python
14
star
36

Projects-my

My solutions to Projects
Python
13
star
37

griddit

orgasmic reddit interface for image-based subreddits
JavaScript
11
star
38

grpc-practical-tutorial

A practical gRPC tutorial
Ruby
10
star
39

Data-Structures-and-Algorithms

Data Structures and Algorithms with Object-Oriented Design Patterns in Python
Python
10
star
40

x-math

Polymer element to embed beautiful math using just HTML.
JavaScript
10
star
41

gphotos-takeout

[WIP] Parse Google Takeout archive for Google Photos
Go
9
star
42

ZipUp

Helping your business go down.. (24-hour hackathon project. Do not try to make sense of code.)
JavaScript
8
star
43

slashStock

Get stock quotes in Twitter. (@slashStock GOOG)
Python
8
star
44

Speekr

Simple app to help learn spoken languages using experimental Chrome APIs
JavaScript
8
star
45

Singular

Mapping the world’s sounds.
JavaScript
8
star
46

statistics.dart

🐎 Functions for calculating mathematical statistics of numeric data.
Dart
7
star
47

Pillar

Suicide prevention app built at a hackathon. See pillar.pdf for pitch slides.
Java
6
star
48

navi

Learn to code together. AngelHack Silicon Valley 2014 Hack.
JavaScript
6
star
49

sopins

Social badges on the fly. (Twitter, Facebook / png, svg)
Python
5
star
50

UW-OpenData

An unofficial data API for UW course catalog.
Python
5
star
51

PHDroid

Product Hunt Android App
Java
5
star
52

PlaySink

A new way to discover music you like.. (One of those things that never really happened)
JavaScript
5
star
53

Flask-Tutorial

Following "The Flask Mega-Tutorial"
Python
5
star
54

AfterLands

Crowdsourced hyperlocal music playlists, Outside Hacks 2014 Project.
JavaScript
4
star
55

unit

A highly modular, fast API framework in Golang, perfectly fitted for Docker
Go
4
star
56

blog-dart

A blog written in Dart
Dart
4
star
57

oss.wtf

Get free subdomains for your OSS projects.
HCL
4
star
58

Gmail-Subject-Lines

Grab subject lines of gmail emails
Python
4
star
59

Zillow

Coding questions for internship @ Zillow
Java
4
star
60

Pixels

Know the pixels you see. A lazy Sunday afternoon hack.
Python
4
star
61

learneveryword

Learn every word in the English language. Task will complete in 2022.
Python
4
star
62

DataStructures

Data structures and algorithms in Java
Java
4
star
63

TakeoverBot

Twitter bot to monitor and respond to tweets promoting state-backed information operations
Go
4
star
64

generator-customelement

A Yeoman generator for scaffolding a Polymer custom element the right way
JavaScript
4
star
65

entroPHy

Product Hunt roulette
CSS
4
star
66

sc-embed

Web component wrapper for embedding SoundCloud tracks
4
star
67

SpamHarvestUW

All my code for analysis done in Spam Harvesting study: https://www.microryza.com/projects/how-do-spammers-harvest-your-e-mail-address
Python
4
star
68

dockerfiles

These are dockerfiles for images I use.
Dockerfile
3
star
69

Python-vs-Java-forks

Visualising usage of Python and Java throughout the world using WebGL Globe
JavaScript
3
star
70

dart-hn

A very basic HN client in Dart.
Dart
3
star
71

MoodicPlayer

Build your last.fm playlist based on your mood.
Java
3
star
72

summarize

A very basic script to summarize any piece of content (text). Still in progress.
Python
3
star
73

Pillar-API

API for backend of Suicide Prevention App
JavaScript
3
star
74

Tech_Poster

A script that posts tech news to /r/technology
Python
2
star
75

oldblog

My old blog
CSS
2
star
76

Euler

My solutions to Project Euler using Python
Python
2
star
77

typeof.dart

typeOf in Dart.
Dart
2
star
78

LastFMSessionKeyFinder

Easily generate Last.FM session key for your developments
Java
2
star
79

ms.dart

Tiny milisecond conversion utility for Dart.
Dart
2
star
80

PyFibonacci

Simple python script that prints fibonacci series
Python
2
star
81

TOPS-GiveCamp

Email marketing system made for Timebanks at GiveCamp Seattle 2013.
JavaScript
2
star
82

baby-tracker-api

Backend to get Jawbone UP data, crunch it and send to the client. PennApps Fall 2014.
JavaScript
2
star
83

Awear

Context aware wearables
JavaScript
2
star
84

Interviews

interview problems and solutions
Python
2
star
85

ThisForThat

A pure Python implementation of itsthisforthat.com
Python
2
star
86

SmartCradle

Saving infant lives by alarming when they sleep with chest down. PennApps Fall 2014.
Arduino
2
star
87

node-slides

JavaScript
1
star
88

inside-api

πŸ˜† See last commit in this repo.
JavaScript
1
star
89

SWSEAedu

All my stuff for Startup Weekend SEA Edu
Python
1
star
90

x-sarcasm

<sarcasm></sarcasm>
HTML
1
star
91

YALT

Yet Another Learning Tool (YALT) is a lightweight and minimal utility to make it easier for you to remember things.
Java
1
star
92

slashZoomEnhance

Zoom, Enhance... on Twitter [doesn't work quite well]
Python
1
star
93

Valyoo

Dumping all my code files for Valyoo Technologies. They will not make any practical sense without the data.
Python
1
star
94

read-wsj

We Know You're Just Going To Google This Headline Anyway, So Here Is A Link To The Free Article, You Cheap Bastard
JavaScript
1
star
95

ARCH-251

My lecture notes for ARCH 251 at UW
1
star
96

have.tips

have.tips homepage
CSS
1
star
97

weebly

A mini-weebly.
JavaScript
1
star
98

ZipUp-private

A public fork of ZipUp that *was* being deployed and actively developed.
Java
1
star
99

pyFizzBuzz

FizzBuzz in Python
Python
1
star
100

Rails-toys

Rails playground
Ruby
1
star