Skip to content

Instantly share code, notes, and snippets.

@hamedrnik
Created June 13, 2016 11:32
Show Gist options
  • Save hamedrnik/05ed1d4cd8c5a254ba11744d56a397ab to your computer and use it in GitHub Desktop.
Save hamedrnik/05ed1d4cd8c5a254ba11744d56a397ab to your computer and use it in GitHub Desktop.
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'] = 'APP_ID'
# Configure API key authorization: app_key
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-Key'] = 'APP_KEY'
# create an instance of the API class
api_instance = aylien_news_api.DefaultApi()
title = '\"electric vehicles\"'
language = ['en']
since = 'NOW-50DAYS'
until = 'NOW'
per_page = 100
period = '+10YEARS'
time_series_response = api_instance.list_time_series(title=title, language=language, published_at_start=since, published_at_end=until, period=period)
# Here is 156 stories count for my query
total = time_series_response.time_series[0].count
print(total)
stories_response = api_instance.list_stories(title=title, language=language, published_at_start=since, published_at_end=until, per_page=per_page)
stories = stories_response.stories
cursor = stories_response.next_page_cursor
stories_response2 = api_instance.list_stories(title=title, language=language, published_at_start=since, published_at_end=until, per_page=per_page, cursor=stories_response.next_page_cursor)
stories_response3 = api_instance.list_stories(title=title, language=language, published_at_start=since, published_at_end=until, per_page=per_page, cursor=stories_response2.next_page_cursor)
# You'll get an empty array, because there are only 156 result and and page 3 as expected is empty
print(stories_response3.stories)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment