def playoff_info(season): data = nhl_api.data.get_playoff_data(season) parsed = data.json() season = parsed["season"] output = {'season': season} try: playoff_rounds = parsed["rounds"] rounds = {} for r in range(len(playoff_rounds)): rounds[str(playoff_rounds[r]["number"])] = MultiLevelObject( playoff_rounds[r]) output['rounds'] = rounds except KeyError: debug.error("No data for {} Playoff".format(season)) output['rounds'] = False try: default_round = parsed["defaultRound"] output['default_round'] = default_round except KeyError: debug.error("No default round for {} Playoff.".format(season)) default_round = 0 output['default_round'] = default_round return output
def playoff_info(season): data = nhl_api.data.get_playoff_data(season) parsed = data.json() season = parsed["season"] output = {'season': season} return output
def scoreboard(year, month, day): """ Return the scoreboard information for games matching the parameters as a dictionary. """ data = nhl_api.data.get_schedule(year, month, day) if not data: return data parsed = data.json() if parsed["dates"]: games_data = parsed["dates"][0]["games"] games = {} for game in games_data: game_id = game['gamePk'] season = game['season'] game_type = game['gameType'] game_date = game['gameDate'] home_team_id = int(game['teams']['home']['team']['id']) home_team_name = game['teams']['home']['team']['name'] away_team_id = int(game['teams']['away']['team']['id']) away_team_name = game['teams']['away']['team']['name'] home_score = game['teams']['home']['score'] away_score = game['teams']['away']['score'] status = game['status']['detailedState'] status_code = game['status']['statusCode'] status_abstract_state = game['status']['abstractGameState'] linescore = game['linescore'] output = { 'game_id': game_id, 'season': season, 'game_type': game_type, 'game_date': game_date, 'home_team_id': home_team_id, 'home_team_name': home_team_name, 'away_team_id': away_team_id, 'away_team_name': away_team_name, 'home_score': home_score, 'away_score': away_score, 'status': status, 'status_code': status_code, 'status_abstract_state': status_abstract_state, 'linescore': linescore, # All the linescore information (goals, sog, periods etc...) } # put this dictionary into the larger dictionary games[game_id] = output return games else: return []
def overview(game_id): data = nhl_api.data.get_overview(game_id) parsed = data.json() # Top level information (General) id = parsed['gamePk'] time_stamp = parsed['gameData']['game'] game_type = parsed['gameData']['game']['type'] status = parsed['gameData']['status']['detailedState'] status_code = parsed['gameData']['status']['statusCode'] status_abstract_state = parsed['gameData']['status']['abstractGameState'] game_date = parsed['gameData']['datetime']['dateTime'] # Sub level information (Details) plays = parsed['liveData']['plays'] linescore = parsed['liveData']['linescore'] away_score = linescore['teams']['away']['goals'] home_score = linescore['teams']['home']['goals'] # Team details away_team_id = parsed['gameData']['teams']['away']['id'] away_team_name = parsed['gameData']['teams']['away']['name'] away_team_abrev = parsed['gameData']['teams']['away']['abbreviation'] home_team_id = parsed['gameData']['teams']['home']['id'] home_team_name = parsed['gameData']['teams']['home']['name'] home_team_abrev = parsed['gameData']['teams']['home']['abbreviation'] output = { 'id': id, # ID of the game 'time_stamp': time_stamp, # Last time the data was refreshed (UTC) 'game_type': game_type, # Type of game ("R" for Regular season, "P" for Post season or playoff) 'status': status, # Status of the game. 'status_code': status_code, 'status_abstract_state': status_abstract_state, 'game_date': game_date, # Date and time of the game 'away_team_id': away_team_id, # ID of the Away team 'away_team_name': away_team_name, #Away team name 'away_team_abrev': away_team_abrev, # Away team name abbreviation 'home_team_id': home_team_id, # ID of the Home team 'home_team_name': home_team_name, # Home team name 'home_team_abrev': home_team_abrev, # Home team name abbreviation 'linescore': linescore, # All the linescore information (goals, sog, periods etc...) 'away_score': away_score, # Away team goals 'home_score': home_score, # Home team goals 'plays': plays # Dictionary of all the plays of the game. } return output
def playoff_info(): data = nhl_api.data.get_playoff_data() parsed = data.json() playoff_data = parsed["rounds"] season = parsed["season"] default_round = parsed["defaultRound"] rounds = {} for round in playoff_data: number = round['number'] name = round['names']['name'] series = round['series'] output = { 'season': season, 'default_round': default_round, 'rounds': rounds } rounds[number] = output return rounds
def team_info(): """ Returns a list of team information dictionaries """ data = nhl_api.data.get_teams() parsed = data.json() teams_data = parsed["teams"] teams = [] for team in teams_data: team_id = team['id'] name = team['name'] abbreviation = team['abbreviation'] team_name = team['teamName'] location_name = team['locationName'] short_name = team['shortName'] division_id = team['division']['id'] division_name = team['division']['name'] #division_abbrev = team['division']['abbreviation'] conference_id = team['conference']['id'] conference_name = team['conference']['name'] official_site_url = team['officialSiteUrl'] franchise_id = team['franchiseId'] try: previous_game = team['previousGameSchedule'] # previous_game = False except: debug.log("No next game detected for {}".format(team_name)) previous_game = False try: next_game = team['nextGameSchedule'] except: debug.log("No next game detected for {}".format(team_name)) next_game = False try: stats = team['teamStats'][0]['splits'][0]['stat'] except: debug.log("No Stats detected for {}".format(team_name)) stats = False roster = {} for p in team['roster']['roster']: person = p['person'] person_id = person['id'] name = HumanName(person['fullName']) first_name = name.first last_name = name.last position_name = p['position']['name'] position_type = p['position']['abbreviation'] position_abbrev = p['position']['abbreviation'] try: jerseyNumber = p['jerseyNumber'] except KeyError: jerseyNumber = "" roster[person_id] = { 'firstName': first_name, 'lastName': last_name, 'jerseyNumber': jerseyNumber, 'positionName': position_name, 'positionType': position_type, 'positionAbbrev': position_abbrev } #print('#{} {} - {} {}'.format(jerseyNumber,position_abbrev,first_name,last_name)) output = { 'team_id': team_id, 'name': name, 'abbreviation': abbreviation, 'team_name': team_name, 'location_name': location_name, 'short_name': short_name, 'division_id': division_id, 'division_name': division_name, #'division_abbrev': division_abbrev, 'conference_id': conference_id, 'conference_name': conference_name, 'official_site_url': official_site_url, 'franchise_id': franchise_id, 'roster': roster, 'previous_game': previous_game, 'next_game': next_game, 'stats': stats } # put this dictionary into the larger dictionary teams.append(output) return teams
def series_record(seriesCode, season): data = data = nhl_api.data.get_series_record(seriesCode, season) parsed = data.json() return parsed["data"]
def player_info(playerId): data = nhl_api.data.get_player(playerId) parsed = data.json() player = parsed["people"][0] return MultiLevelObject(player)
def team_info(): """ Returns a list of team information dictionaries """ data = nhl_api.data.get_teams() parsed = data.json() teams_data = parsed["teams"] teams = [] for team in teams_data: team_id = team['id'] name = team['name'] abbreviation = team['abbreviation'] team_name = team['teamName'] location_name = team['locationName'] short_name = team['shortName'] division_id = team['division']['id'] division_name = team['division']['name'] #division_abbrev = team['division']['abbreviation'] conference_id = team['conference']['id'] conference_name = team['conference']['name'] official_site_url = team['officialSiteUrl'] franchise_id = team['franchiseId'] try: previous_game = team['previousGameSchedule'] # previous_game = False except: debug.log("No next game detected for {}".format(team_name)) previous_game = False try: next_game = team['nextGameSchedule'] except: debug.log("No next game detected for {}".format(team_name)) next_game = False try: stats = team['teamStats'][0]['splits'][0]['stat'] except: debug.log("No Stats detected for {}".format(team_name)) stats = False output = { 'team_id': team_id, 'name': name, 'abbreviation': abbreviation, 'team_name': team_name, 'location_name': location_name, 'short_name': short_name, 'division_id': division_id, 'division_name': division_name, #'division_abbrev': division_abbrev, 'conference_id': conference_id, 'conference_name': conference_name, 'official_site_url': official_site_url, 'franchise_id': franchise_id, 'previous_game': previous_game, 'next_game': next_game, 'stats': stats } # put this dictionary into the larger dictionary teams.append(output) return teams
def overview(game_id): data = nhl_api.data.get_overview(game_id) parsed = data.json() # Top level information (General) id = parsed['gamePk'] time_stamp = parsed['gameData']['game'] game_type = parsed['gameData']['game']['type'] status = parsed['gameData']['status']['detailedState'] status_code = parsed['gameData']['status']['statusCode'] status_abstract_state = parsed['gameData']['status']['abstractGameState'] game_date = parsed['gameData']['datetime']['dateTime'] # Sub level information (Details) plays = parsed['liveData']['plays'] linescore = parsed['liveData']['linescore'] boxscore = parsed['liveData']['boxscore'] away_score = linescore['teams']['away']['goals'] home_score = linescore['teams']['home']['goals'] # Team details away_team_id = parsed['gameData']['teams']['away']['id'] away_team_name = parsed['gameData']['teams']['away']['name'] away_team_abrev = parsed['gameData']['teams']['away']['abbreviation'] home_team_id = parsed['gameData']['teams']['home']['id'] home_team_name = parsed['gameData']['teams']['home']['name'] home_team_abrev = parsed['gameData']['teams']['home']['abbreviation'] # 3 stars (if any available) try: first_star = parsed['liveData']['decisions']['firstStar'] second_star = parsed['liveData']['decisions']['secondStar'] third_star = parsed['liveData']['decisions']['thirdStar'] except: first_star = {} second_star = {} third_star = {} output = { 'id': id, # ID of the game 'time_stamp': time_stamp, # Last time the data was refreshed (UTC) 'game_type': game_type, # Type of game ("R" for Regular season, "P" for Post season or playoff) 'status': status, # Status of the game. 'status_code': status_code, 'status_abstract_state': status_abstract_state, 'game_date': game_date, # Date and time of the game 'away_team_id': away_team_id, # ID of the Away team 'away_team_name': away_team_name, #Away team name 'away_team_abrev': away_team_abrev, # Away team name abbreviation 'home_team_id': home_team_id, # ID of the Home team 'home_team_name': home_team_name, # Home team name 'home_team_abrev': home_team_abrev, # Home team name abbreviation 'linescore': linescore, # All the linescore information (goals, sog, periods etc...) 'boxscore': boxscore, # All the boxscore information (players, onice, team's stats, penalty box etc...) 'away_score': away_score, # Away team goals 'home_score': home_score, # Home team goals 'plays': plays, # Dictionary of all the plays of the game. 'first_star': first_star, 'second_star': second_star, 'third_star': third_star } return output