def get_current_game_stats(person_id, params=None): """This endpoint allows you to pull the current game status for a given player. Args: person_id (int): Unique PLayer Identifier params (dict): Contains the person_ids, season, group, and fields parameters described below. params: person_id (required) Description: Unique Player Identifier Parameter Type: path Data Type: integer group *may not yet do anything Description: Category of statistics to return. 0: hitting, 1: pitching, 2: fielding, 3: running Format: 0, 1, 2, 3 Parameter Type: query Data Type: array[string] timecode Description: Use this parameter to return a snapshot of the data at the specified time. Format: YYYYMMDD_HHMMSS fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] Returns: json """ return request(7, 'stats/game/current', primary_key=person_id, params=params)
def get_game_stats(person_id, game_pk, params=None): """This endpoint allows you to pull the game stats for a given player and game. Args: person_id (int): Unique PLayer Identifier game_pk (int): Unique Primary Key representing a game. params (dict): Contains the group, and fields parameters described below. params: person_id (required) Description: Unique Player Identifier Parameter Type: path Data Type: integer game_pk (required) Description: Unique Primary Key representing a game. Parameter Type: path Data Type: integer group *may not yet do anything Description: Category of statistics to return. 0: hitting, 1: pitching, 2: fielding, 3: running Format: 0, 1, 2, 3 Parameter Type: query Data Type: array[string] fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] Returns: json """ return request(7, 'stats/game', primary_key=person_id, secondary_key=game_pk, params=params)
def get_boxscore(game_pk, params=None): """This endpoint allows you to pull the boxscore for a game. Args: game_pk (int): The game primary key params (dict): Contains the timecode and fields parameters described below. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: integer? #string elsewhere in documentation timecode Description: Use this parameter to return a snapshot of the data at the specified time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] Returns: json """ return request(4, 'boxscore', primary_key=game_pk, params=params)
def get_live_timestamps(game_pk, params=None): """ This can be used for replaying games. Endpoint returns all of the timecodes that can be used with diffs for mlbgame.game.live_diff. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: string """ return request(4, 'feed/live/timestamps', primary_key=game_pk, params=params)
def get_content(game_pk, params=None): """ Retrieve game content such as highlights. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: integer? #string elsewhere in documentation highlightLimit: Description: Number of results to return Parameter Type: query Data Type: integer """ return request(4, 'content', primary_key=game_pk, params=params)
def get_win_probability(game_pk, params=None): """ params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: integer? #string elsewhere in documentation timecode Description: Use this parameter to return a snapshot of the data at the specified time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] """ return request(4, 'winProbability', primary_key=game_pk, params=params)
def get_live_diff(game_pk, params=None): """ This endpoint allows comparison of game files and shows any differences or discrepancies between the two. Diff/Patch System: startTimecode and endTimecode can be used for getting diffs. Expected usage: 1) Request full payload by not passing startTimecode or endTimecode. This will return the most recent game state. 2) Find the latest timecode in this response. 3) Wait X seconds 4) Use the timecode from 2 as the startTimecode. This will give you a diff of everything that has happened since startTimecode. 5) If no data is returned, wait X seconds and do the same request. 6) If data is returned, get a new timeStamp from the response, and use that for the next call as startTimecode. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: string startTimecode Description: Start time code will give you everything since that time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string endTimecode Description: End time code will give you a snapshot at that specific time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string """ return request(4, 'feed/live/diffPatch', primary_key=game_pk, params=params)
def get_color_diff(game_pk, params=None): """ This API can return very large payloads. It is STRONGLY recommended that clients ask for diffs and use "Accept-Encoding: gzip" header. startTimecode and endTimecode can be used for getting diffs. Expected usage: 1) Request full payload by not passing startTimecode or endTimecode. This will return the entire color feed up till the current time. 2) Find the latest timecode in this response. 3) Wait X seconds 4) Use the timecode from 2 as the startTimecode. This will give you a diff of everything that has happened since startTimecode. 5) If no data is returned, wait X seconds and do the same request. 6) If data is returned, get a new timeStamp from the response, and use that for the next call as startTimecode. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: string startTimecode Description: Start time code will give you everything since that time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string endTimecode Description: End time code will give you a snapshot at that specific time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string """ return request(4, 'feed/color/diffPatch', primary_key=game_pk, params=params)
def get_live(game_pk, params=None): """ This API can return very large payloads. It is STRONGLY recommended that clients ask for diffs and use "Accept-Encoding: gzip" header. params: game_pk (required) Description: Unique Primary Key Representing a Game Parameter Type: path Data Type: string timecode Description: Use this parameter to return a snapshot of the data at the specified time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] """ return request(4, 'feed/live', primary_key=game_pk, params=params)
def get_person(person_id, params=None): """This endpoint allows you to pull the information for a player. Args: person_id (int): Unique Player Identifier params (dict): Contains the person_ids, season, group, and fields parameters described below. params: person_id (required) Description: Unique Player Identifier Parameter Type: path Data Type: integer person_ids Description: Comma delimited list of person ID. Format: 1234, 2345 Parameter Type: query Data Type: array[integer] season Description: Season of play Parameter Type: query Data Type: string group *may not yet do anything Description: Category of statistics to return. 0: hitting, 1: pitching, 2: fielding, 3: running Format: 0, 1, 2, 3 Parameter Type: query Data Type: array[string] fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] Returns: json """ return request(7, primary_key=person_id, params=params)
def get_schedule(params={'sportId': 1, 'date': TODAY}): """ This endpoint allows you to pull shedules. params: calendarTypes Description: Comma delimitd list of type of events Parameter Type: query Data Type: array[string] teamId Description: Unique Team Identifier. Format: 141, 147, etc. Parameter Type: query Data Type: array[integer] leagueId Description: Unique League Identifier Parameter Type: query Data Type: array[integer] sportId Description: Top level organization of a sport Format: SportId is 1 for MLB Parameter Type: query Data Type: array[integer] gamePk Description: Unique Primary Key representing a game Parameter Type: query Data Type: integer gamePks Description: Comma delimited list of unique primary keys Parameter Type: query Data Type: array[integer] eventIds Description: A unique identifier for non-game event Parameter Type: query Data Type: array[integer] venueIds Description: Unique Venue Identifier Parameter Type: query Data Type: array[integer] performerIds Description: A unique identifier for non-team event performers Parameter Type: query Data Type: array[integer] gameType Description: Type of Game. Available types in api/v1/gameTypes Parameter Type: query Data Type: array[string] gameTypes Description: Comma delimited list of type of Game. Parameter Type: query Data Type: array[string] season Description: Season of play Parameter Type: query Data Type: array[string] seasons Description: Comma delimited list of seasons of play Parameter Type: query Data Type: array[string] date Description: Date of Game Format: MM/DD/YYYY Parameter Type: query Data Type: LocalDate startDatem Description: Start date for range of data. Must be used with end date. Format: MM/DD/YYYY Parameter Type: query Data Type: LocalDate endDate Description: End date for range of data. Must be used with start date. Format: MM/DD/YYYY Parameter Type: query Data Type: LocalDate timecode Description: Use this parameter to return a snapshot of the data at the specified time. Format: YYYYMMDD_HHMMSS Parameter Type: query Data Type: string useLatestGames Description: userLatestGames??? Parameter Type: query Data Type: boolean opponentId Description: A unique identifier for the opposing team. Must be usted with teamId. Parameter Type: query Data Type: integer (Documentation says array[integer]) fields Description: Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute Parameter Type: query Data Type: array[string] """ if 'startDate' in params.keys(): if 'endDate' not in params.keys(): error = 'Query contains startDate with no endDate.' raise mlbgame.exceptions.ScheduleParamaterException(error) if 'endDate' in params.keys(): if 'startDate' not in params.keys(): error = 'Query contains endDate with no startDate.' raise mlbgame.exceptions.ScheduleParamaterException(error) if 'opponentId' in params.keys(): if 'teamId' not in params.keys(): error = 'Query contains opponentId with no teamId.' raise mlbgame.exceptions.ScheduleParamaterException(error) return request(8, 'schedule', params=params)