Closed mustseetv314 closed 8 months ago
Thanks for the heads up! Looks like there is another update to the mlb api and we will need to add that field to game details
Thanks for the heads up! Looks like there is another update to the mlb api and we will need to add that field to game details
All good, appreciate it. Use this all the time, so kudos to ya'll. Great stuff!
Thanks for the heads up! Looks like there is another update to the mlb api and we will need to add that field to game details
Hey KC! Any ETA on when ya'll will make this code fix? Thanks!
@KCNilssen any ETA for the fix here? Thanks!
I'm sorry I'll go ahead and fix this now
Can you share your code?
I have no issues with gamepk 717885 @mustseetv314
sure @Mattsface ill run it again and post code
@Mattsface @KCNilssen
Code snipet plus 2 .csv attached: Input = mlb_games.csv output = mlb_games_ready.csv --As you can see, it grabs the venue name, lat, long, elevation, surface for some...but errors with for some...PlayDetails.init()
mlb_games.csv mlb_games_ready.csv
pip list
csv_file = 'mlb_games.csv' df = pd.read_csv(csv_file)
df['venue_id'] = None df['venue_name'] = None df['venue_latitude'] = None df['venue_longitude'] = None df['venue_elevation'] = None df['venue_surface'] = None
for index, row in df.iterrows(): game_pk = row['GamePk'] print(game_pk) try: venue_id, venue_name, venue_lat, venue_long, venue_elevation, venue_surface = get_game_info(game_pk) df.at[index, 'venue_id'] = venue_id df.at[index, 'venue_name'] = venue_name df.at[index, 'venue_latitude'] = venue_lat df.at[index, 'venue_longitude'] = venue_long df.at[index, 'venue_elevation'] = venue_elevation df.at[index, 'venue_surface'] = venue_surface except Exception as e: print(f"Error processing game_pk {game_pk}: {e}")
new_column_order = [ 'Date', 'Time', 'GamePk', 'Away Team', 'Home Team', 'venue_id', 'venue_name', 'venue_latitude', 'venue_longitude', 'venue_elevation', 'venue_surface']
assert set(new_column_order) == set(df.columns), "New column order does not match DataFrame columns"
df = df[new_column_order]
updated_csv_file = 'mlb_games_ready.csv' df.to_csv(updated_csv_file, index=False)
Function:
def get_game_info(game_pk):
mlb = mlbstatsapi.Mlb()
try:
game = mlb.get_game(game_pk)
venue_id = game.gamedata.venue.id
venue_name = game.gamedata.venue.name
venue_lat = game.gamedata.venue.location.defaultcoordinates.latitude
venue_long = game.gamedata.venue.location.defaultcoordinates.longitude
venue_elevation = game.gamedata.venue.location.elevation
venue_surface = game.gamedata.venue.fieldinfo.turftype
return venue_id, venue_name, venue_lat, venue_long, venue_elevation, venue_surface
except Exception as e:
print(f"Error processing game_pk {game_pk}: {e}")
return "None", "None", "None", "None", "None", "None"
@mustseetv314 Your issue should be resolved now, let us know If you have any more issues
@KCNilssen @Mattsface looks good now gents, appreciate it!
Upgraded to: python-mlb-statsapi 0.5.17 and errors are now gone.
Note: I'm using the latest version of: python-mlb-statsapi 0.5.16 MLB-StatsAPI 1.7.1
This function broke after the topperformers class update 2 weeks ago:
For some game_pk's the information returns as expected, but for a few(errors below) I'm receiving a PlayDetails.init() error, and I can't find that class in the repository: PlayDetails.init() got an unexpected keyword argument 'violation'
Code: def get_game_info(game_pk): mlb = mlbstatsapi.Mlb() try: game = mlb.get_game(game_pk) venue_id = game.gamedata.venue.id venue_name = game.gamedata.venue.name venue_lat = game.gamedata.venue.location.defaultcoordinates.latitude venue_long = game.gamedata.venue.location.defaultcoordinates.longitude venue_elevation = game.gamedata.venue.location.elevation venue_surface = game.gamedata.venue.fieldinfo.turftype return venue_id, venue_name, venue_lat, venue_long, venue_elevation, venue_surface except Exception as e: print(f"Error processing game_pk {game_pk}: {e}")
return "None", "None", "None", "None", "None", "None"
ERROR(For example processing 2023-06-03 game_pk's): 717885 Error processing game_pk 717885: PlayDetails.init() got an unexpected keyword argument 'violation'