def __init__(self, searchQuery, number_articles, NewsAPIKey): # Get News API Information self.news_api = newsapi_client.NewsApiClient(api_key=NewsAPIKey) self.tokenizer = nltk.data.load('tokenizers/punkt/english.pickle') self.search_query = searchQuery self.number_articles = number_articles self.article_content = [] self.sentences = [] self.main_execution()
from newsapi import newsapi_client import datetime import json api = newsapi_client.NewsApiClient(api_key='d022b69b02b3488ebd2508c2b3972734') date = datetime.datetime(2018, 9, 20) # print(date.strftime('%Y-%m-%d')) all_articles = [] for i in range(30): all_articles.append( api.get_everything(q='Google', from_param=date.strftime('%Y-%m-%d'), to=date.strftime('%Y-%m-%d'), language='en', sort_by='relevancy', page=2)) with open('JsonFile{}.json'.format(i), 'w') as fp: json.dump(all_articles[i], fp) print(date) print(all_articles[i]) date += datetime.timedelta(days=1) # with open('JsonFile1.json','w') as fp: # jsonString = json.dump(all_articles,fp)
return everything def Hotlines(self, _topic, _source, _category, _language, _country): hotlines = apikey.get_top_headlines(q=_topic, sources=_source, category=_category, language=_language, country=_country) return hotlines def Sources(self, _category, _language, _country): sources = apikey.get_sources(category=_category, language=_language, country=_country) return apikey = newsapi_client.NewsApiClient( api_key='c6ad02b14a8e4089a9f0bbc6f44c2d6c') request_news = News() top_headlines = apikey.get_top_headlines(q='trump', sources='CNN', language='en') print(top_headlines) print(top_headlines['articles'][0]) print(type(top_headlines['articles'][0])) # interact with frontend # get the latest news to display (sports, movie,etc)