hnclient


Namehnclient JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryPython client for Hacker News API with cached API calls built in.
upload_time2023-11-27 16:35:47
maintainer
docs_urlNone
authorInquestGeronimmo
requires_python
license
keywords python hacker-news api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Hacker News Client  <img align="right" width="75" height="75" src="./img/hackernews-logo.png">

The Hacker News Client is a Python-based tool designed to seamlessly engage with the official Hacker News Firebase API. This client incorporates a built-in request-cache mechanism for each API call, allowing for the efficient handling of complete data dumps without the need for redundant subsequent calls. This feature significantly optimizes your data wrangling processes, saving you time and resources.

## Install <img align="center" width="23" height="23" src="https://media.giphy.com/media/sULKEgDMX8LcI/giphy.gif">
<br>

```
pip install hnclient
```

## Quick Start <img align="center" width="23" height="23" src="https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif">
<br>

First step is to initialize `HackerNewsClient` prior to making an API request. By default, client requests are cached. To disable cache, set the `disable_cache` argument to **True**:

```py
from hnclient import HackerNewsClient

client = HackerNewsClient()
```

To fetch stories from Hacker News, begin by using the **getstories** method. 

- :bulb: You can select specific story section by passing its name into the **story** argument. Here are few  examples: `Top`, `Best`, `Ask`, `Show`. 

- :bulb: You can also set the sorting order for all stories by their Hacker News score with the `descending` argument. Default is `False`.

```py
from hnclient import HackerNewsClient

client = HackerNewsClient()

data = client.get_stories("top", descending=False)
print(data)
```
The program above will print out a list of dictionaries where each dictionary holds the following metadata per story: :point_down:

```text
{'author': 'tristanho',
 'comments': 156,
 'id': 34006202,
 'score': 318,
 'text': 'Hey HN, cofounder of Readwise here. We&#x27;ve been working on this '
          'cross-platform reader app for about 2 years, excited to finally...'   ,
 'time': 1671140643,
 'title': 'Show HN: Readwise Reader, an all-in-one reading app',
 'url': 'https://readwise.io/read'}

```

## Data Wrangling <img align="center" width="23" height="23" src="https://media.giphy.com/media/hRYXatty4dJks/giphy.gif">
<br>

1. Collect a list of a specific metadata object. The available list of objects can be found in the printed dictionary above. For the example below, we are obtaining a list of all URLS pertaining to the **Top** stories:

```py
from hnclient import HackerNewsClient

client = HackerNewsClient()
data = client.get_stories("top")

urls = client.get_item("url", data)
print(urls)
```
&emsp; outputs:

```
    ['https://github.com/ifeelalright1970/ytmp',
     'https://mimosa.so/',
     'https://www.screen.studio/',
     'https://www.pinetarpoker.com',
    ...]
```

2. Select a random story from the client payload. For the example below, we are obtaiing a story pertaining from the **Best** stories.

```py
from hnclient import HackerNewsClient

client = HackerNewsClient()
data = client.get_stories("best")

random = client.get_random_story(data)
print(random)
```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "hnclient",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,hacker-news,api",
    "author": "InquestGeronimmo",
    "author_email": "rcostanl@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bf/fc/984b9783a7ea1371f969c600d667e2ec2d518ce6acca8b09c61eb69dbc8b/hnclient-0.0.2.tar.gz",
    "platform": null,
    "description": "\n# Hacker News Client  <img align=\"right\" width=\"75\" height=\"75\" src=\"./img/hackernews-logo.png\">\n\nThe Hacker News Client is a Python-based tool designed to seamlessly engage with the official Hacker News Firebase API. This client incorporates a built-in request-cache mechanism for each API call, allowing for the efficient handling of complete data dumps without the need for redundant subsequent calls. This feature significantly optimizes your data wrangling processes, saving you time and resources.\n\n## Install <img align=\"center\" width=\"23\" height=\"23\" src=\"https://media.giphy.com/media/sULKEgDMX8LcI/giphy.gif\">\n<br>\n\n```\npip install hnclient\n```\n\n## Quick Start <img align=\"center\" width=\"23\" height=\"23\" src=\"https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif\">\n<br>\n\nFirst step is to initialize `HackerNewsClient` prior to making an API request. By default, client requests are cached. To disable cache, set the `disable_cache` argument to **True**:\n\n```py\nfrom hnclient import HackerNewsClient\n\nclient = HackerNewsClient()\n```\n\nTo fetch stories from Hacker News, begin by using the **getstories** method. \n\n- :bulb: You can select specific story section by passing its name into the **story** argument. Here are few  examples: `Top`, `Best`, `Ask`, `Show`. \n\n- :bulb: You can also set the sorting order for all stories by their Hacker News score with the `descending` argument. Default is `False`.\n\n```py\nfrom hnclient import HackerNewsClient\n\nclient = HackerNewsClient()\n\ndata = client.get_stories(\"top\", descending=False)\nprint(data)\n```\nThe program above will print out a list of dictionaries where each dictionary holds the following metadata per story: :point_down:\n\n```text\n{'author': 'tristanho',\n 'comments': 156,\n 'id': 34006202,\n 'score': 318,\n 'text': 'Hey HN, cofounder of Readwise here. We&#x27;ve been working on this '\n          'cross-platform reader app for about 2 years, excited to finally...'   ,\n 'time': 1671140643,\n 'title': 'Show HN: Readwise Reader, an all-in-one reading app',\n 'url': 'https://readwise.io/read'}\n\n```\n\n## Data Wrangling <img align=\"center\" width=\"23\" height=\"23\" src=\"https://media.giphy.com/media/hRYXatty4dJks/giphy.gif\">\n<br>\n\n1. Collect a list of a specific metadata object. The available list of objects can be found in the printed dictionary above. For the example below, we are obtaining a list of all URLS pertaining to the **Top** stories:\n\n```py\nfrom hnclient import HackerNewsClient\n\nclient = HackerNewsClient()\ndata = client.get_stories(\"top\")\n\nurls = client.get_item(\"url\", data)\nprint(urls)\n```\n&emsp; outputs:\n\n```\n    ['https://github.com/ifeelalright1970/ytmp',\n     'https://mimosa.so/',\n     'https://www.screen.studio/',\n     'https://www.pinetarpoker.com',\n    ...]\n```\n\n2. Select a random story from the client payload. For the example below, we are obtaiing a story pertaining from the **Best** stories.\n\n```py\nfrom hnclient import HackerNewsClient\n\nclient = HackerNewsClient()\ndata = client.get_stories(\"best\")\n\nrandom = client.get_random_story(data)\nprint(random)\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python client for Hacker News API with cached API calls built in.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [
        "python",
        "hacker-news",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "611be7bad32ff4e9745614da58623af8f7530b2363d71a856f143173e537dd0a",
                "md5": "2a2fe643a7f7c6e365dad011922ccc00",
                "sha256": "feace38a5f376342d15d5f8845c2084cff5c9727d09c92bf490865c4cfb5c4e5"
            },
            "downloads": -1,
            "filename": "hnclient-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a2fe643a7f7c6e365dad011922ccc00",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9724,
            "upload_time": "2023-11-27T16:35:46",
            "upload_time_iso_8601": "2023-11-27T16:35:46.479752Z",
            "url": "https://files.pythonhosted.org/packages/61/1b/e7bad32ff4e9745614da58623af8f7530b2363d71a856f143173e537dd0a/hnclient-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bffc984b9783a7ea1371f969c600d667e2ec2d518ce6acca8b09c61eb69dbc8b",
                "md5": "7af8b9a1fec0d2587376711c7cc34176",
                "sha256": "5d03bc212f85923f1bd533ed783033edf4429183052ae7d87664411225aa86f6"
            },
            "downloads": -1,
            "filename": "hnclient-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7af8b9a1fec0d2587376711c7cc34176",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8800,
            "upload_time": "2023-11-27T16:35:47",
            "upload_time_iso_8601": "2023-11-27T16:35:47.493836Z",
            "url": "https://files.pythonhosted.org/packages/bf/fc/984b9783a7ea1371f969c600d667e2ec2d518ce6acca8b09c61eb69dbc8b/hnclient-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 16:35:47",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "hnclient"
}
        
Elapsed time: 0.14224s