Closed rationalpastime closed 8 years ago
How did you get the ID for that game? It is not listed by the MLB on the scoreboard for that game. The MLB also has no stats for that game. I can't really do anything if the data is not provided by MLB.com.
It was one of the game IDs your module generated it via mlbgame.day(2016, 4, 4). I know you can't get the data if the data aren't provided. I mention this in case you wanted to build in some error checking before your module tries to pull a URL that doesn't exist. When your module tries to pull one of those pages and gets an error, it stops whatever program is running it dead in its tracks.
I will add some sort of try/except for that.
Note: also seems to happen with some rainouts, for instance last night's Royals/Sox game. The following code generates the same error.
game = mlbgame.day(2016, 5, 16, home="Royals")[0] stats = mlbgame.player_stats(game.game_id)
Super useful module otherwise.
I think you could check the game_type
to determine if the game was rained out or not.
Also, I do not know if I want to make the requests silently fail. Without showing the error message, it could break parts of programs when they try to use what is returned from the function.
Alright I'll give that a shot. I get not wanting errors to silently fall, though I thought it might be possible to catch them, return a message and then continue on with a routine. Maybe not. I'm a novice coder.
I think it would be more beneficial for the user to try/catch so they at least know that something didn't work right.
Also, thanks for using mlbgame.
In case anyone runs into the same trouble I did, I thought I'd post the workaround I'm using. I use the mlbgame.game.scoreboard module to generate a list of game IDs with finals. For instance, for the games of May 16, 2016, I use:
statuslist = []
finalgames = []
for game in list(mlbgame.game.scoreboard(2016, 5, 16).keys()):
game_status = (mlbgame.game.scoreboard(2016, 5, 16)[game]['game_status'])
game_id_status = [game, game_status]
statuslist.append(game_id_status)
for item in statuslist:
if item[1] == 'FINAL':
finalgames.append(item)
This creates a list of MLB Game IDs named finalgames
that only includes IDs from games with finals. That list doesn't always play nice with other modules, but when it doesn't it's easy to use scoreboard to get the data I need with my custom list.
Occasionally MLB teams play non-MLB teams in exhibition. Two of these games took place on April 4, 2016. combine_games handles this okay, simply ignoring the non-MLB match-ups. See the April 4 scoreboard:
However, player_stats does not handle these well. Below is the error message I receive when I try to run mlbgame.player_stats(game.game_id) on one of those games, for instance the Miami Marlins vs. the Diablos Rojos: