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
#Your API email: smithe57@uni.coventry.ac.uk
#Your API token: 5dfd9c58254f4aeeb754655a5b8cae09
import http.client
import json
def teamInformation(example):
"""Returns information about the team entered"""
overview=[]
#**Most of the following code is from https://www.football-data.org/documentation/samples
connection = http.client.HTTPConnection('api.football-data.org')
headers = { 'X-Auth-Token': '5dfd9c58254f4aeeb754655a5b8cae09' }
connection.request('GET', '/v2/teams/{}'.format(example), None, headers )
response = json.loads(connection.getresponse().read().decode())
#**END
team_name = (response['name'])
team_year = str(response['founded'])
team_colours = (response['clubColors'])
overview.append("The team")
overview.append(team_name)
overview.append("was created in the year")
overview.append(team_year)
overview.append("they wear the colours")
overview.append(team_colours)
return(" ".join(overview))
def playerInformation(example):
"""Returns information about the players in the team selected"""
overview=[]
#**Most of the following code is from https://www.football-data.org/documentation/samples
connection = http.client.HTTPConnection('api.football-data.org')
headers = { 'X-Auth-Token': '5dfd9c58254f4aeeb754655a5b8cae09' }
connection.request('GET', '/v2/teams/{}'.format(example), None, headers )
response = json.loads(connection.getresponse().read().decode())
#**END
overview.append('This team has the following players:')
for i in range(0,15):
player_name = (response['squad'][i]['name'])
overview.append(player_name + ',')
player_name = (response['squad'][16]['name'])
overview.append('and ' + player_name + '.') #OCD (End of sentence)
return (" ".join(overview))
def List():
"""Returns a list of teams and their corresponding codes"""
List = ['57 - Arsenal', '58 - Aston Villa',
'59 - Blackburn', '60 - Bolton',
'61 - Chelsea', '62 - Everton',
'63 - Fulham', '64 - Liverpool',
'65 - Manchester City', '66 - Manchester United',
'67 - Newcastle United', '68 - Norwich',
'69 - QPR', '70 - Stoke',
'71 - Sunderland', '72 - Swansea',
'73 - Tottenham', '74 - West Brom',
'75 - Wigan', '76 - Wolves'
]
return ('\n'.join(List))
teamlist = ('57','58','59','60','61','62','63','64','65','66','67','68','68','69','70','71','72','73','74','75','76')
if __name__ == "__main__":
while True:
Example = input("What team would you like to know about? ")
Example.split()
if Example=='q':
print('see you next time')
break
else:
if Example.lower() in teamlist:
print(teamInformation(Example))
print('\n')
print(playerInformation(Example))
elif '/team' in Example.lower():
print(List())
else:
print("Im still learning new teams. Please make sure you entered the team number.\nYou can find team numbers by doing the command '/team'")