An unofficial Hacker News API Client Library in Python
Project description
hnconnector: An unofficial Hacker News API Client Library in Python
hnconnector is a lightweight Python library designed to simplify accessing the Hacker News API. With hnconnector, you can easily fetch stories, comments, user profiles, and other data from Hacker News with minimal setup. Whether you're building a custom Hacker News reader, analyzing Hacker News stories, or integrating Hacker News data into your projects, hnconnector provides a straightforward Pythonic interface to interact with Hacker News.
Features
- Fetch top, new, and best stories from Hacker News
- Retrieve details about specific stories, comments, and users
- Access Ask HN, Show HN, and job stories
- Simple and intuitive API
Installation
hnconnector can be installed using pip. Ensure you have Python 3.6 or higher installed on your system. To install hnconnector, open your terminal and run:
pip install hnconnector
Quick Start
Here's a quick example to get you started by fetching the top stories from Hacker News:
from hn import Client
client = Client()
# Fetch top stories
top_stories = client.get_topstories()
print("Top 10 Hacker News Stories IDs:")
for story_id in top_stories[:10]:
print(story_id)
# Fetch details for a specific story
story_details = client.get_item(top_stories[0])
print(f"Details of the top story: {story_details}")
Usage
Initializing the Client
Create an instance of the Client class to start interacting with the API:
from hn import Client
client = Client()
Fetching Stories
You can fetch different types of stories (top, new, best, ask HN, show HN, and jobs) as follows:
top_stories = client.get_topstories()
new_stories = client.get_newstories()
best_stories = client.get_beststories()
ask_stories = client.get_askstories()
show_stories = client.get_showhn()
job_stories = client.get_jobstories()()
Retrieving an Item
To retrieve details about a specific item (story, comment, etc.), use its ID:
item_id = 16582136
item_details = client.get_item(item_id)
print(item_details)
Fetching User Profiles
username = 'dang'
user_details = client.get_user(username)
print(user_details['karma'])
Contributing
Contributions to hnconnector are welcome!
License
hnconnector is released under the MIT License. See the LICENSE file for more details.
Contact
For questions or feedback regarding hnconnector, please open an issue on the GitHub repository: https://github.com/mfiro/hnconnector.
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 hnconnector-0.1.2.tar.gz
.
File metadata
- Download URL: hnconnector-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28bd780eebd5604c25dbf3c2860f6e8c89255d8a02cd0a6acfcc4b3041128741 |
|
MD5 | 9c074b71d71fed77dd7a8c764756aaac |
|
BLAKE2b-256 | ae597f1d20033099458bb3d9e5b115baf7623d2c1674095975fd33ce8ac3741a |
File details
Details for the file hnconnector-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: hnconnector-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f15c1976eb20357db6415226b271a8687c43f7e3abb0606bb377f33f84b36cc8 |
|
MD5 | e242f5b2bfed15b9b5e309493ace3b3e |
|
BLAKE2b-256 | b6d868401e4a105f66671e99861972ba410db91caef7d9192f21da9966b0b6b2 |