Skip to main content

Python Hacker News API Wrapper

A minimalistic wrapper for the Hacker News API

Installation

Via PIP:

pip install hnapi

To install the latest development version:

git clone https://github.com/IThinkImOKAY/hnapi
cd hnapi
pip install .

Usage

Import the wrapper:

>>> from hnapi import hackernews

Set your user agent:

>>> hn = hackernews(user_agent='[description]:[version] by @[username]')

Get an item:

Returns a dictionary

>>> hn.item('1')
{'by': 'pg', 'descendants': 15, 'id': 1, 'kids': [15, 234509, 487171, 454426, 454424, 454410, 82729], 'score': 57, 'time': 1160418111, 'title': 'Y Combinator', 'type': 'story', 'url': 'http://ycombinator.com'}

Get a user:

Returns a dictionary

>>> hn.user('test')
{'about': '', 'created': 1175289467, 'delay': 0, 'id': 'test', 'karma': 1, 'submitted': [1043201, 1029445, 1026445, 586568, 418362, 418361, 11780]}

Get the max item:

Returns an integer

>>> hn.max_item()
27743784

Get stories by type:

Returns a list of integers

The get_stories() function takes a required kind argument. It must be one of the following:

  • ‘new’

  • ‘top’

  • ‘best’

  • ‘ask’

  • ‘show’

  • ‘job’

>>> hn.get_stories(kind='ask')
[27743303, 27742459, 27743368, 27742048, 27739960, 27739957, 27743011, 27719928, 27741278, 27740921, 27740599, 27729059, 27737668, 27722254, 27739126, 27738779, 27733316, 27737402, 27736487, 27736404, 27736293, 27710539, 27729202, 27710097, 27740763, 27725805, 27730349, 27727072, 27710270, 27734110, 27730677, 27736526, 27740141, 27727802, 27720970, 27731873, 27735679, 27728069, 27718990, 27718806, 27727403, 27722579, 27722321, 27714299, 27729577, 27721200, 27720447, 27715246, 27711355, 27710263, 27717304, 27716627, 27725274, 27742922, 27742599, 27741124, 27740932, 27740744, 27740658, 27740465, 27740187, 27739064, 27738847, 27738710, 27738663, 27738404, 27738247]

Get changed items:

Returns a list of integers

>>> hn.changed_items()
[27743787, 27743786, 27743217, 27742092, 27740163, 27743304, 27741560, 27743687, 27742448, 27740617, 27742512, 27743782, 27740550, 27741551, 27743573, 27743454, 27741466, 27743468, 27743603, 27743751, 27743412, 27743649, 27742124, 27743632, 27743773, 27739665, 27742073, 27742149, 27734473, 27743427, 27743665, 27740936, 27741910, 27743303, 27739596, 27734676, 27737064, 27738312, 27743788, 27741026, 27742824, 27740204, 27737718]

Get changed profiles:

Returns a list of strings

>>> hn.changed_profiles()
['floatingatoll', 'asd3rz', 'nrmitchi', 'plorkyeran', 'shivekkhurana', 'danudey', 'billyharris', 'Lammy', 'reaperducer', 'BugWatch', 'trdtaylor1', 'kennywinker']

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hnapi-0.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

hnapi-0.0.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file hnapi-0.0.0.tar.gz.

File metadata

  • Download URL: hnapi-0.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3

File hashes

Hashes for hnapi-0.0.0.tar.gz
Algorithm Hash digest
SHA256 d0f2065a338af99a8ff11c6f5ba168fce519c1a5176ddeaa6e94b5048a29f9a0
MD5 0d1cc58d77f383aa09e4f2ab9dbaf2d5
BLAKE2b-256 7721b574374a39b9bbc90ad88aa9ae8b44234bb402635e9d0fb60014451cc306

See more details on using hashes here.

File details

Details for the file hnapi-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: hnapi-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3

File hashes

Hashes for hnapi-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc08ef42475d33b08bd677cf0be2e291e1474b0a0adf80867555ece5418c25ca
MD5 7104d208c3de5f25ba216b2f9de1b5b0
BLAKE2b-256 ae3c700716e4b79dc6bd57af8db04055032cf3d3a9f5dd6806d29f221ca56644

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 files

Supported by

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