Skip to main content

Add your description here

Project description

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

Usage

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

I'm in the process of updating this project and migrating to uv. You should be able to just do:

$ uv run py.test

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

python_hn-0.0.4.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_hn-0.0.4-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_hn-0.0.4.tar.gz.

File metadata

  • Download URL: python_hn-0.0.4.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for python_hn-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1a4276fcfa31470b1efc5819a85acf06a2e0bc367620022d84c6f9e9232d629a
MD5 a5b7fddddff1d654a4cfa1aa0a7aa614
BLAKE2b-256 3a0f2b8f11d34b8448ddc89cb3048fb597f03bcc799defd902d41552fe0db40f

See more details on using hashes here.

File details

Details for the file python_hn-0.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_hn-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6f189dc49e87dab6fdf263c4a4479c47180e0088e238c542eb5a6c1e74041ac7
MD5 4813e16f47a5cfaaa738461c3119d68a
BLAKE2b-256 babef13a05e55271fa6dcc5b24985c636b934f85218a72a26f048489d5668de7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page