Skip to content

Instantly share code, notes, and snippets.

@hamedrnik
Created June 16, 2016 15:09
Show Gist options
  • Select an option

  • Save hamedrnik/17c2eba01d9403d5dda9ba0c60abb401 to your computer and use it in GitHub Desktop.

Select an option

Save hamedrnik/17c2eba01d9403d5dda9ba0c60abb401 to your computer and use it in GitHub Desktop.
import aylien_news_api
from aylien_news_api.rest import ApiException
from functools import reduce
# 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()
first_params = {
'language': ['en'],
'per_page': 100,
'since': '2016-06-14T00:00:00Z',
'until': '2016-06-14T23:59:59Z',
'source_domain': [
'news24.com',
'irishtimes.com',
'independent.co.uk',
'seekingalpha.com',
'theguardian.com',
'thehindubusinessline.com',
'theglobeandmail.com',
'washingtonpost.com',
'france24.com',
'forbes.com',
'ft.com',
'edition.cnn.com',
'aljazeera.com',
'punchng.com',
'nytimes.com',
'shanghaidaily.com',
'bbc.co.uk',
'business-standard.com',
'allafrica.com',
'fastcompany.com',
'cbsnews.com',
'wsj.com',
'ibtimes.com',
'zdnet.com',
'telegraph.co.uk',
'abcnews.go.com',
'businessinsider.com',
'thestreet.com',
'newsweek.com',
'bloomberg.com',
'salon.com',
'businessoffashion.com',
'hurriyetdailynews.com',
'japantoday.com',
'techcrunch.com',
'thestar.com',
'huffingtonpost.com'
],
'title': 'exxonmobil OR exxon OR petrochina OR microsoft OR "china mobile" OR wal-mart OR walmart OR "wal mart" OR ge OR "general electric" OR roche OR facebook OR "j.p. morgan" OR "jp morgan" OR jpmorgan OR ccb OR "china construction bank" OR pfizer OR anheuser-busch OR "anheuser busch" OR inbev OR verizon OR tencent OR gilead OR "agricultural bank of china" OR shell OR "walt disney" OR merck OR "home depot" OR pepsico OR pepsi OR comcast OR "novo nordisk" OR cisco OR unilever OR bp OR "british petroleum" OR "ping an insurance" OR "philip morris" OR unitedhealth OR qualcomm OR santander OR boeing OR bms OR "bristol-myers squibb" OR mastercard OR inditex OR altria OR ambev OR "british american tobacco"'
}
second_params = first_params.copy()
second_params['since'] = '2016-05-14T00:00:00Z'
first_time_series_response = api_instance.list_time_series(title=first_params['title'], language=first_params['language'], published_at_start=first_params['since'], published_at_end=first_params['until'], source_domain=first_params['source_domain'])
second_time_series_response = api_instance.list_time_series(title=second_params['title'], language=second_params['language'], published_at_start=second_params['since'], published_at_end=second_params['until'], source_domain=second_params['source_domain'])
# Here is 63 stories count for the first query
#total1 = first_time_series_response.time_series[0].count
total1 = reduce((lambda x, y: x + y), list(map((lambda x: x.count), first_time_series_response.time_series)))
print(total1)
# Here is 1531 stories count for the second query
#total2 = second_time_series_response.time_series[0].count
total2 = reduce((lambda x, y: x + y), list(map((lambda x: x.count), second_time_series_response.time_series)))
print(total2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment