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 optionsstory,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. Exampleponts__lt=100lte(<=): Lower than or equals to. Exampleponts__lte=100gt(>): Greater than. Examplecreated_at__gt='2018'(created after 2018-01-01).gte(>=): Greater than or equals to. Examplenum_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a4276fcfa31470b1efc5819a85acf06a2e0bc367620022d84c6f9e9232d629a
|
|
| MD5 |
a5b7fddddff1d654a4cfa1aa0a7aa614
|
|
| BLAKE2b-256 |
3a0f2b8f11d34b8448ddc89cb3048fb597f03bcc799defd902d41552fe0db40f
|
File details
Details for the file python_hn-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: python_hn-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f189dc49e87dab6fdf263c4a4479c47180e0088e238c542eb5a6c1e74041ac7
|
|
| MD5 |
4813e16f47a5cfaaa738461c3119d68a
|
|
| BLAKE2b-256 |
babef13a05e55271fa6dcc5b24985c636b934f85218a72a26f048489d5668de7
|