A wrapper library for Hacker News Search API (provided by Algolia)
Project description
HackerNews / Algolia Python Library
This is a simple library to interface with HN Search API (provided by Algolia).
Install instructions
$ pip install python-hn
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 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=100
lte
(<=
): Lower than or equals to. Exampleponts__lte=100
gt
(>
): 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]
Roadmap
- V0.0.3: Post type aliases
- V0.0.2 CURRENT: Functioning API
- V0.0.1: Initial Version
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
File details
Details for the file python-hn-0.0.3.tar.gz
.
File metadata
- Download URL: python-hn-0.0.3.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8328cb8d247ff59fde65206005779f05fb52267455fba017582a914a47cce633 |
|
MD5 | 8b571cd38de800d7cb2db63c8b138342 |
|
BLAKE2b-256 | 51f01906a01d4a6714e7dde30dddb9d04b1bc3740f9719dfbda100abec9ce6be |
File details
Details for the file python_hn-0.0.3-py2.py3-none-any.whl
.
File metadata
- Download URL: python_hn-0.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc7b7cfeb350f09a564c40d431a538aefacb8eebba2162e3ab1ee70db19463b |
|
MD5 | 8f26ca63ef893bfbfcb73b7982ab5a40 |
|
BLAKE2b-256 | 413b3d0d0507e62aaaa63a46cd4e083f28f8a66fbbf8fd1052e403b8c91ff227 |