Mar-28-2020, 10:25 PM
Joeylax54 Wrote:I'm just getting started with Python so bear with me lol, there are currently 32 different roster endpoints (one for each team).Here some hints on a start and use Requests.
So can collect all data bye iterate over all urls.
Then it look like this,try figure name_search function so can search for Ryan Miller and return back 8468011.
import requests def nhl_all(): nhl_lst = [] for team in range(1,31): url = f'https://statsapi.web.nhl.com/api/v1/teams/{team}/roster' response = requests.get(url) json_data = response.json() nhl_lst.append(json_data) return nhl_lst def name_search(json_data, name): pass if __name__ == '__main__': json_data = nhl_all() print(json_data) #name = 'Ryan Miller' #print(name_search(json_data, name)) # 8468011 ''' Test data name = 'Ryan Miller' # https://statsapi.web.nhl.com/api/v1/teams/24/roster # 8468011 '''