Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ChatBot_A6/News.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (27 sloc)
1.37 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This module was written primarily by Vinayak Sareen and edited slightly by Humza Shahid for GUI integration. | |
#To see Vinayak's original work, compare this file with the other News.py in this repository. This News.py contains Humza's changes. | |
import requests | |
def newsFunc(newsSource): | |
''' Gets news source from GUI, then returns article titles and URLs ''' | |
News_Source = ['','https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=991c214e1ef4461cbae43df7805cafde','https://newsapi.org/v1/articles?source=the-times-of-india&sortBy=top&apiKey=991c214e1ef4461cbae43df7805cafde',"https://newsapi.org/v1/articles?source=the-new-york-times&sortBy=top&apiKey=991c214e1ef4461cbae43df7805cafde"] | |
articleList = [] | |
urlList = [] | |
if newsSource == "bbc": | |
User_news_source = 1 | |
elif newsSource == "times of india": | |
User_news_source = 2 | |
elif newsSource == "new york times": | |
User_news_source = 3 | |
else: | |
return None | |
Source = News_Source[User_news_source] | |
response = requests.get(Source).json() | |
Index_range = len(response['articles']) - 1 | |
for index in range(0,Index_range) : | |
try: | |
article = response['articles'][index]['title'] | |
articleList.append(article) | |
urlList.append(response['articles'][index]['url']) | |
except TypeError: | |
continue | |
return(articleList, urlList) |