{ "info": { "author": "samisnotinsane", "author_email": "sameen11@hotmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# hackernews-client\n\n[![CircleCI](https://circleci.com/gh/samisnotinsane/hackernews-client/tree/master.svg?style=svg)](https://circleci.com/gh/samisnotinsane/hackernews-client/tree/master)\n[![codebeat badge](https://codebeat.co/badges/651aecbd-aba5-4631-9246-fce7bca9a382)](https://codebeat.co/projects/github-com-samisnotinsane-hackernews-client-master)\n[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://opensource.org/licenses/mit-license.php)\n\nUse this wrapper library to download Hacker News headlines into your Python program. \n\n## Getting Started\n\nThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. \n\n### Prerequisites\n\nYou will need the python-requests library so we can make HTTP calls. Install with pip:\n\n```\npip install requests\n```\n\n### Installing\n\nIn your Terminal\n\n```\ngit clone https://github.com/samisnotinsane/hackernews-client.git\ncd hackernews-client\n```\n\nRun the example script: `news.py`\n\n```\npython news.py\n```\n\nthis fetches:\n - Best stories\n - Search\n - story\n - comment\n - poll\n - job\n - Most recent items (last `n` items)\n\n\n\nYou may make another copy of this script\n\n```\ncp news.py ./my_copy_news.py\npython my_copy_news.py\n```\n\nmodifying it to suit your use case.\n\n## Running the tests\n\nThis package contains tests which verifies the integrity of the internal logic.\n\n### Unit tests\n\nTo run all unit tests, make sure you're in the root directory (`hackernews-client`). Use Python's built in `unittest` library\n\n```\npython -m unittest -v\n```\n\nIf you have clone from `master` branch, these should always pass. At the time of testing, sometimes these tests failed with `SSLErrors` due to too many requests being made to the Hacker News API too quickly. Wait ~20 secs before running the unit tests again.\n\nAlternatively, it could be that a breaking change was made to the Web API which would require updating this library. Feel free to raise an [Issue](https://github.com/samisnotinsane/hackernews-client/issues) or a [Pull Request](https://github.com/samisnotinsane/hackernews-client/pulls) to remediate the problem.\n\n## Usage\n\nBegin by importing the library. This example assumes you're working within `news.py` in the root directory of the repo.\n\n```\nfrom hackernews import hn\n```\n\nThe client is then initialised in the following way\n\n```\nnews_client = hn.NewsClient()\n```\n\nIn this case, `news_client` object gives access to all available methods. The data contained in the methods and the instances returned all closely follow the [HackerNews API](https://github.com/HackerNews/API).\n\nYou may retrieve a list of best `10` stories in the following way\n\n```\nnews_client.get_best_story(fetchMax=10)\n```\n\nadjusting the value of `fetchMax` up to and including a maximum of `500`.\n\nFor completeness, full documentation with examples are provided below.\n\n## Documentation\n\n### Class: `NewsClient`\n\n- `get_item`\n\n**Parameters:**\n\n\n| Name | Type | Required | Description | Default\n| ---------- | ---- | -------- | --------------------------------------------- | -------\n| `item_id` | int | Yes | unique item id of Hacker News story, comment etc | None\n\nReturns:\na list of `Item` (each of type `dict`). See class documentation for `Item` which contains a full description of each property.\n\n\n- `get_top_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 500 | 500\n\nReturns:\na list of top stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/topstories.json`\n\n- `get_ask_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 200 | 200\n\nReturns:\na list of Ask HN stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/askstories.json`\n\n- `get_new_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 500 | 500\n\nReturns:\na list of new stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/newstories.json`\n\n- `get_show_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 200 | 200\n\nReturns:\na list of Show HN stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/showstories.json`\n\n- `get_best_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 200 | 200\n\nReturns:\na list of best stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/beststories.json`\n\n- `get_job_story`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----------- | ------- | ----------- | --------------------------------------- | -------\n| `fetchMax` | int | Yes | Number of stories to fetch, max value = 200 | 200\n\nReturns:\na list of job stories as `Item` from the url `https://hacker-news.firebaseio.com/v0/jobstories.json`\n\n- `get_max_item_id`\n\n**Parameters:** None\n\nReturns:\n`int` of the largest item id from the url: `https://hacker-news.firebaseio.com/v0/maxitem.json`\n\n- `get_item_by_id`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----- | ---- | -------- | ------------------------------------- | -------\n| `id` | int | Yes | unique `Item` id of Hacker News story | None\n\nReturns:\n`Item` representing the Hacker News story with given `id` fetched\nfrom url: `https://hacker-news.firebaseio.com/v0/item/.json`\n\n- `get_user_by_id`\n\n**Parameters:**\n\n| Name | Type | Required | Description | Default\n| ----- | ---- | -------- | ------------------------------------- | -------\n| `id` | int | Yes | unique `Item` id of Hacker News story | None\n\nReturns:\n`User` representing the Hacker News user with given `id` fetched\nfrom url: `https://hacker-news.firebaseio.com/v0/user/.json`\n\n### Class: `Item`\n\nStories, comments, jobs, Ask HNs and even polls are just items. They're identified by their ids, which are unique integers.\n\nField | Description\n------|------------\nid | The item's unique id.\ndeleted | `true` if the item is deleted.\ntype | The type of item. One of \"job\", \"story\", \"comment\", \"poll\", or \"pollopt\".\nby | The username of the item's author.\ntime | Creation date of the item, in [Unix Time](http://en.wikipedia.org/wiki/Unix_time).\ntext | The comment, story or poll text. HTML.\ndead | `true` if the item is dead.\nparent | The comment's parent: either another comment or the relevant story.\npoll | The pollopt's associated poll.\nkids | list of `Item` of this item's comments, in ranked display order.\nurl | The URL of the story.\nscore | The story's score, or the votes for a pollopt.\ntitle | The title of the story, poll or job.\nparts | A list of related pollopts, in display order.\ndescendants | In the case of stories or polls, the total comment count.\n\n### Class: `User`\n\nUsers are identified by case-sensitive ids. Only users that have public activity (comments or story submissions) on the site are available through the API.\n\nField | Description\n------|------------\n**id** | The user's unique username. Case-sensitive. Required.\ndelay | Delay in minutes between a comment's creation and its visibility to other users.\n**created** | Creation date of the user, in [Unix Time](http://en.wikipedia.org/wiki/Unix_time).\n**karma** | The user's karma.\nabout | The user's optional self-description. HTML.\nsubmitted | List of the user's stories, polls and comments.\n\n## Screenshot\n\n![Hacker News Client](/screenshots/hackernews-client-screenshot.png?raw=true \"Bash shell running example.py script\")\n\n## Authors\n\n* **Sameen Islam** - [samisnotinsane](https://github.com/samisnotinsane)\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE.md file for details\n\n## Acknowledgments\n\n* Author of [haxor](https://github.com/avinassh/haxor) whose library inspired me to make my first Python library\n* Author of [python-packaging](http://veekaybee.github.io/2017/09/26/python-packaging/) whose tutorial helped me get my head around the Python import system", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/samisnotinsane/hackernews-client", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "hackernews-client", "package_url": "https://pypi.org/project/hackernews-client/", "platform": "", "project_url": "https://pypi.org/project/hackernews-client/", "project_urls": { "Homepage": "https://github.com/samisnotinsane/hackernews-client" }, "release_url": "https://pypi.org/project/hackernews-client/0.1.2b1/", "requires_dist": null, "requires_python": ">=3.6.0", "summary": "An unofficial but simple Python client for Hacker News Web API.", "version": "0.1.2b1" }, "last_serial": 5710279, "releases": { "0.1.2b1": [ { "comment_text": "", "digests": { "md5": "5d70ce23b27893f8505f3508334f4adb", "sha256": "854e9a97808bdff4cd5acfbdf07644f0ddd0ba9136a521a3c42ac587fc02524d" }, "downloads": -1, "filename": "hackernews-client-0.1.2b1.tar.gz", "has_sig": false, "md5_digest": "5d70ce23b27893f8505f3508334f4adb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 8080, "upload_time": "2019-08-21T15:03:14", "url": "https://files.pythonhosted.org/packages/d2/c5/8cb8d095743698272937551b1bed0b79d899d8c8f9d550407e499c3d5abf/hackernews-client-0.1.2b1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5d70ce23b27893f8505f3508334f4adb", "sha256": "854e9a97808bdff4cd5acfbdf07644f0ddd0ba9136a521a3c42ac587fc02524d" }, "downloads": -1, "filename": "hackernews-client-0.1.2b1.tar.gz", "has_sig": false, "md5_digest": "5d70ce23b27893f8505f3508334f4adb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 8080, "upload_time": "2019-08-21T15:03:14", "url": "https://files.pythonhosted.org/packages/d2/c5/8cb8d095743698272937551b1bed0b79d899d8c8f9d550407e499c3d5abf/hackernews-client-0.1.2b1.tar.gz" } ] }