panzarino/mlbgame

Team schedules+start times

Closed this issue · 6 comments

I'm fairly certain this is a problem with my code but hoping it's close enough that someone can help get it finished. The code below is supposed to pull the date, start time and weather for White Sox home games in April and May. The only issue is it produces the April 24th game twice and leaves out the April 26th game. Still relatively new to python so any help would be greatly appreciated.

import pandas as pd
import mlbgame
import os
#----------------------------------------------------------------------------------------------------#

team = 'White Sox'
park = 'U.S. Cellular Field'

year = 2015
months = [4,5]
#----------------------------------------------------------------------------------------------------#
    
for month in months:
    games = mlbgame.games(year, month, away=team, home=team)

    for game in games:
        game = game[0]

        if game.game_status == 'FINAL':

            try:
                overview = mlbgame.overview(game.game_id)      
            except ValueError:
                pass

            if overview.venue_name == park:
                print(overview.date)           
                print(overview.start_time)
                print(overview.weather)

@chisox721 are you sure that there was a game on that day? Your code looks sound so there might be an issue with the library because the library should be getting all the games correctly in the mlbgame.games function.

@panzarino According to BRef and Fangraphs they played on Fri April 24th and Sun April 26th. Sat April 25th game was rained out...maybe the root issue has something to do with that?

Also, I was using ValueError to skip over games without ID's but wasn't really sure that was right.

@chisox721 I think the fact that the game was cancelled is why it is not showing up. However, I do not understand why the game for the 24th is showing up twice. I'll look into it.

@panzarino Just to give you an update on this, I was working with 2018 schedules and the Cubs game on April 14th appeared 3 times (April 15th and 16th games were postponed).

So the issue is basically that cancelled games are replaced with the most recent completed game instead of being skipped. Are you sure it's not a problem with my code? Maybe the except ValueError is causing the issue.

@chisox721 Honestly, I do not know what the issue is. I'll try to do some testing and see what's going on when I get the time.

@panzarino No worries, very easy for me to work around it. Just figured I'd let you know.