About
This is the Python client for AYLIEN News API.
Requirements
Python 2.7 and 3.4+
Installation
PyPI
Install it directly from PyPI repository:
pip install aylien_news_api
(or sudo pip install aylien_news_api
to install the package for all users)
Git
Install it via:
pip install git+https://github.com/AYLIEN/aylien_newsapi_python.git
(you may need to run pip
with root permission: sudo pip install git+https://github.com/AYLIEN/aylien_newsapi_python.git
)
Getting Started
Please follow the installation instruction and execute the following code:
import aylien_news_api
from aylien_news_api.rest import ApiException
# Configure API key authorization: app_id
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-ID'] = 'YOUR_APP_ID'
# Configure API key authorization: app_key
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-Key'] = 'YOUR_APP_KEY'
# create an instance of the API class
api_instance = aylien_news_api.DefaultApi()
opts = {
'title': 'trump',
'sort_by': 'social_shares_count.facebook',
'language': ['en'],
'not_language': ['es', 'it'],
'published_at_start': 'NOW-7DAYS',
'published_at_end': 'NOW',
'entities_body_links_dbpedia': [
'http://dbpedia.org/resource/Donald_Trump',
'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
]
}
try:
# List stories
api_response = api_instance.list_stories(**opts)
print("API called successfully. Returned data: ")
print("========================================")
for story in api_response.stories:
print(story.title + " / " + story.source.name)
except ApiException as e:
print("Exception when calling DefaultApi->list_stories: %s\n" % e)