Skip to content
A library wrapper for Hacker News Search API (Powered by Algolia)
Jupyter Notebook Python
Branch: master
Clone or download
Latest commit 03e0fd5 Jul 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
hn Fixes #5: Users endpoint Dec 7, 2018
tests Fixes #5: Users endpoint Dec 7, 2018
.gitignore Initial commit Nov 15, 2018
.travis.yml Final travis versions Dec 8, 2018
DEMO.ipynb Add how to run instruction on top of DEMO file Dec 10, 2018
LICENSE Bumped version to 0.0.2 Nov 16, 2018
MANIFEST.in Bumped version to 0.0.2 Nov 16, 2018
README.md Update README.md Jul 20, 2019
demo.yml Implement DEMO.ipynb and demo.yml files Dec 5, 2018
dev-requirements.txt Setup scripts Nov 16, 2018
requirements.txt Setup scripts Nov 16, 2018
setup.cfg Setup scripts Nov 16, 2018
setup.py Travis test fixes Dec 8, 2018

README.md

HackerNews / Algolia Python Library

This is a simple library to interface with HN Search API (provided by Algolia).

Install | Basic Usage | Development | Roadmap

👉 Note: As an example, I used this library to download ALL Hacker News posts and made it available as a public dataset in Kaggle.

Install instructions

$ pip install python-hn

Demo

Get hands on python-hn in this interactive demo online:

Usage

Check out Interactive Docs to try the library without installing it.

from hn import search_by_date

# Search everything (stories, comments, etc) containing the keyword 'python'
search_by_date('python')

# Search everything (stories, comments, etc) from author 'pg' and keyword 'lisp'
search_by_date('lisp', author='pg', created_at__lt='2018-01-01')

# Search only stories
search_by_date('lisp', author='pg', stories=True, created_at__lt='2018-01-01')

# Search stories *or* comments
search_by_date(q='lisp', author='pg', stories=True, comments=True, created_at__lt='2018-01-01')
Tags

Tags are part of HN Search API provided by Algolia. You can read more in their docs. They can form complex queries, for example:

# All the comments in the story `6902129`
tags = PostType('comment') & StoryID('6902129')

The available tags are:

  • PostType: with options story, comment, poll, pollopt, show_hn, ask_hn, front_page.
  • Author: receives the username as param (Author('pg')).
  • StoryID: receives the story id (StoryID('6902129'))
Filters

Filters can be applied to restrict the search by:

  • Creation Date: created_at
  • Points: points
  • Number of comments: num_comments

They can accept >, <, >=, <= operators with a syntax similar to Django's.

  • lt (<): Lower than. Example ponts__lt=100
  • lte (<=): Lower than or equals to. Example ponts__lte=100
  • gt (>): Greater than. Example created_at__gt='2018' (created after 2018-01-01).
  • gte (>=): Greater than or equals to. Example num_comments__gte=50.

Examples (See Algolia docs for more info):

# Created after October 1st, 2018
search_by_date(created_at__gt='2018-10')

# Created after October 1st, 2017 and before January 1st 2018
search_by_date(created_at__gt='2018-10', created_at__lt='2018')

# Stories with *exactly* 1000 points
search_by_date(tags=PostType('story'), points=1000)

# Comments with more than 50 points
search_by_date(tags=PostType('comment'), points__gt=50)

# Stories with 100 comments or more
search_by_date(tags=PostType('story'), num_comments__gt=100)
Search

[TODO]

Development

Current milestone: https://github.com/santiagobasulto/python-hacker-news/milestone/2

Roadmap

  • V0.0.4: Other endpoints: /search, /users, /items (CURRENT)
  • V0.0.3: Post type aliases, improved API
  • V0.0.2: Functioning API
  • V0.0.1: Initial Version
You can’t perform that action at this time.