A Python client for the GNews API with category, country, and language filtering
Project description
GNews IO Client
A Python client for the gnews.io APIs that supports category, country, and language filtering.
Installation
pip install gnewsio
Usage
from gnews.client_builder import Gnews
from gnews.enums import Category, Country, Language
from datetime import datetime
API_KEY = "YOUR_API_KEY"
gnews_client = (Gnews(api_key=API_KEY)
.set_category(Category.NATION)
.set_country(Country.UNITED_STATES)
.set_language(Language.ENGLISH)
.set_max_article_count(2)
.set_from_date(datetime(2024, 10, 11, 0, 0, 0)) # YYYY-MM-DDThh:mm:ssZ
.set_to_date(datetime(2024, 10, 11, 23, 59, 59)) # YYYY-MM-DDThh:mm:ssZ
.build())
# Response as JSON
response = gnews_client.fetch_top_headlines(to_json=True)
print(response)
# Response as Articles
try:
response = gnews_client.fetch_top_headlines()
print(f"Total Articles: {response.total_articles}")
for article in response.articles:
print(article)
except Exception as e:
print(f"Error: {e}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gnewsio-0.1.6.tar.gz
(5.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gnewsio-0.1.6.tar.gz.
File metadata
- Download URL: gnewsio-0.1.6.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
971d7cbf84a62a628c548d408e402ba8efc78ae573eab07329f49204977623ad
|
|
| MD5 |
7195916f9118271040b04d9ebb06d18c
|
|
| BLAKE2b-256 |
ffb78771bbecef870de23feceaf346717a0651768b974119e5e41570c16ad1fa
|
File details
Details for the file gnewsio-0.1.6-py3-none-any.whl.
File metadata
- Download URL: gnewsio-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73c25b651e9fca8c5838f29ef23d320cea331f7cf17be538980467ae43a480da
|
|
| MD5 |
ea2553269afd179e4a561eccbbb86a23
|
|
| BLAKE2b-256 |
ac97959dd4f06dd708685281e531eeb0cfe6a7e66958db77ef6d62228f269b07
|