Example #1
0
def home(request):
	api = NewsApiClient(api_key=config('newsAPI'))
	all_articles = api.get_everything(q='blaze', language='en', sort_by='relevancy')
	publisher = {}
	for article in all_articles['articles']:
		if article['source']['name'] not in publisher and article['content'] is not None:
			publisher[article['source']['name']] = {'url': '', 'content': '', 'title': '', 'image': ''}
			publisher[article['source']['name']]['url'] = article['url']
			publisher[article['source']['name']]['content'] = article['content']
			publisher[article['source']['name']]['title'] = article['title']
			publisher[article['source']['name']]['image'] = article['urlToImage']

	auth = tweepy.OAuthHandler(config('consumer_key'), config('consumer_secret'))
	auth.set_access_token(config('access_token'), config('access_token_secret'))
	api = tweepy.API(auth)

	tweets = api.search('mumbai fire casualties', count=5)
	texts = ''
	for tweet in tweets:
		texts += str(TextBlob(tweet.text)) + ' || '
	return render(request, 'app/home.html', {'publisher': publisher, 'texts': texts})