Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hockey Data Project
#8
I found the simple solution to find players from different teams
NHL_url = 'http://statsapi.web.nhl.com'

url_extension = '?hydrate=stats(splits=statsSingleSeason)'
url_teams = 'https://statsapi.web.nhl.com/api/v1/teams'
url_teams2 = 'https://statsapi.web.nhl.com/api/v1/teams/'
url_roster_extension = '/roster'

with urlopen(url_teams) as response:
    source = response.read()
    data = json.loads(source)
    for teams in data['teams']:
        team_id2 = teams['id']
        url_full2 = url_teams2 + str(team_id2) + url_roster_extension
        url_roster = url_full2
        with urlopen(url_roster) as response:
            source = response.read()
            data = json.loads(source)
            for item in data['roster']:
                if item['person']['fullName'] == Player_Name:
                    if item['position']['code'] == 'G':
                        goalie_code = (item['person']['link'])
                        url_full = NHL_url + str(goalie_code) + url_extension
                        with urlopen(url_full) as response:
                            source = response.read()
                            data = json.loads(source)
                            for item5 in data['people']:
                                print('')
                                print(item5['fullName'])
                                for item2 in item5['stats']:
                                    for item3 in item2['splits']:
                                        wins = item3['stat']['wins']
                                        losses = item3['stat']['losses']
                                        goalsAgainst = item3['stat']['goalsAgainst']
                                        shotsAgainst = item3['stat']['shotsAgainst']
                                        evenSaves = item3['stat']['evenSaves']
                                        savePercentage = item3['stat']['savePercentage']
                                        goalagainstaverage = item3['stat']['goalAgainstAverage']
                                        print('')
                                        print('Wins: ', wins)
                                        print('Losses: ', losses)
                                        print('GA: ', goalsAgainst)
                                        print('SA: ', shotsAgainst)
                                        print('SV: ', evenSaves)
                                        print('SV%: ', savePercentage, '%')
                                        print('GAA: ', goalagainstaverage, )
Reply


Messages In This Thread
Hockey Data Project - by Joeylax54 - Mar-24-2020, 05:13 PM
RE: Hockey Data Project - by ndc85430 - Mar-24-2020, 07:17 PM
RE: Hockey Data Project - by Joeylax54 - Mar-24-2020, 08:07 PM
RE: Hockey Data Project - by ndc85430 - Mar-25-2020, 03:30 AM
RE: Hockey Data Project - by Joeylax54 - Mar-26-2020, 08:25 PM
RE: Hockey Data Project - by ndc85430 - Mar-28-2020, 05:16 PM
RE: Hockey Data Project - by snippsat - Mar-28-2020, 10:25 PM
RE: Hockey Data Project - by Joeylax54 - Mar-29-2020, 05:20 AM
RE: Hockey Data Project - by yummykudos - Apr-18-2020, 02:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020