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 by Rahul Verma and edited slightly by Humza Shahid.
import requests # request module is required.
# https://newsapi.org/
def espnAPI():
request = requests.get("https://newsapi.org/v1/articles?source=espn&sortBy=top&apiKey=01dff295c83e4b2da79345b4cb2e1175").json()
# ^this reads the data within the url above
json_status = request['status']
articleList = []
descriptionList = []
urlList = []
for x in range(0, 5): #for loop implemented to provide the top 5 sports stories
articleList.append(request['articles'][x]['title'].upper())
descriptionList.append(request['articles'][x]['description'])
urlList.append(request['articles'][x]['url'])
return articleList, descriptionList, urlList
def bbc_sportsAPI():
bbc_sports = requests.get("https://newsapi.org/v1/articles?source=bbc-sport&sortBy=top&apiKey=7235bbbb3da84015b4154b00f948c9fd").json()
# ^this reads the data within the url above
bbc_sports_status = bbc_sports['status']
articleList = []
descriptionList = []
urlList = []
for x in range(0, 5): #for loop implemented to provide the top 5 sports stories
articleList.append(bbc_sports['articles'][x]['title'].upper())
descriptionList.append(bbc_sports['articles'][x]['description'])
urlList.append(bbc_sports['articles'][x]['url'])
return articleList, descriptionList, urlList
def sports_BibleAPI():
sports_bible = requests.get("https://newsapi.org/v1/articles?source=the-sport-bible&sortBy=top&apiKey=01dff295c83e4b2da79345b4cb2e1175").json()
sports_bible_status = sports_bible['status']
# ^this reads the data within the url above
articleList = []
descriptionList = []
urlList = []
for x in range(0, 5): #for loop implemented to provide the top 5 sports stories
articleList.append(sports_bible['articles'][x]['title'].upper())
descriptionList.append(sports_bible['articles'][x]['description'])
urlList.append(sports_bible['articles'][x]['url'])
return articleList, descriptionList, urlList
def sports_menu():
"""The Menu where the user chooses the source of the news"""
print("###### SPORTS NEWS ######")
print("1. ESPN Sports News")
print("2. BBC Sports News")
print("3. Sports Bible News")
print("#########################")
print("")
menu = input("Enter News Number: ")
if menu == 1:
espnAPI()
elif menu == 2:
bbc_sportsAPI()
elif menu == 3:
sports_BibleAPI()
else:
sports_menu()
#sports_menu()