Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#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)