seatgeek / api-support

A support channel for the SeatGeek Platform
9 stars 10 forks source link

Events endpoint for MLB games returned schedule does not match MLB schedule #80

Closed gr33ngiant112 closed 5 years ago

gr33ngiant112 commented 5 years ago

Hi,

My companies building is right next to an MLB stadium and the parking garage is closed during day games or jacked up to event pricing.

I want to use the seatgeek API to get a list of all scheduled Red's day games that fall between Monday-Friday and occur between 9 AM and 4 PM in the afternoon and create an ics (iCal) calendar with the filtered day games schedule.

I'm not sure if my filter is incorrect or not but when calling a list of all Cincinnati Red's home games, filtering for day of the week and occurring between 9AM and 4PM, I get a list back thats missing at least 1, maybe more games when compared with the official MLB schedule for the Cincinnati Reds.

In the code below, I'm only getting all Cincinnati Reds that occur during the regular season in which the Reds are the home team and the venue city is Cincinnati (I've tried without the venue city argument, no change in results).

Code:

def get_events(performer_id, endpoint, current_year, client_id, client_secret, proxies):
    events_endpoint = endpoint + '/events'
    params = {
        'client_id': client_id,
        'client_secret': client_secret,
        'performers[home_team].id': performer_id,
        'datetime_utc.gte': f"{current_year}-03-28",
        'datetime_utc.lte': f"{current_year}-10-30",
        'venue.city': 'Cincinnati',
        'per_page': 100,
        'format':'json'
    }
    request = requests.get(
        url=events_endpoint, 
        params=params, 
        proxies=proxies, 
        verify=False, 
        auth=(client_id, client_secret)
    ).json()

    return request

Formatted output from a python dict built from the filter events api call:

Milwaukee Brewers at Cincinnati Reds 2019-09-26T12:35:00
Miami Marlins at Cincinnati Reds 2019-04-11T12:35:00
St. Louis Cardinals at Cincinnati Reds 2019-08-18T13:10:00
Atlanta Braves at Cincinnati Reds 2019-04-25T18:40:00
San Francisco Giants at Cincinnati Reds 2019-05-06T12:35:00
Chicago Cubs at Cincinnati Reds 2019-08-11T13:10:00
Los Angeles Dodgers at Cincinnati Reds 2019-05-19T13:10:00
Pittsburgh Pirates at Cincinnati Reds 2019-07-31T12:35:00
Pittsburgh Pirates at Cincinnati Reds (Rescheduled from March 30, 2019) 2019-05-27T19:10:00
Washington Nationals at Cincinnati Reds 2019-06-02T13:10:00
Texas Rangers at Cincinnati Reds 2019-06-16T13:10:00
Houston Astros at Cincinnati Reds 2019-06-19T12:35:00
Cleveland Indians at Cincinnati Reds 2019-07-07T13:10:00
Colorado Rockies at Cincinnati Reds 2019-07-28T13:10:00
Los Angeles Angels at Cincinnati Reds 2019-08-06T19:10:00
San Diego Padres at Cincinnati Reds 2019-08-21T12:35:00
Philadelphia Phillies at Cincinnati Reds 2019-09-05T12:35:00
Arizona Diamondbacks at Cincinnati Reds 2019-09-08T13:10:00
New York Mets at Cincinnati Reds 2019-09-22T13:10:00

Notice this list is missing the following game:

https://www.mlb.com/reds/schedule/2019-04/list?homeGame=true&nightGame=false Apr 3 Wed | Reds vs.Brewers | 12:35 pm EDT

However, through the SeatGeek UI, I can see the game: https://seatgeek.com/brewers-at-reds-tickets/4-3-2019-cincinnati-ohio-great-american-ball-park/mlb/4609733

What am I doing wrong? I've poured over the documentation, tried changing the date range filter, adding a time to the datetime_utc flter, and several other things with no results. I compared my parsed calendar output to the MLB schedule for the Cincinnati Reds home games and there are several others missing as well.

Any help would be greatly appreciated.

Thanks!

dallasgutauckis commented 5 years ago

Just to be clear, it seems you're saying the 2019-04-03 game is missing from the response, not the 2019-04-11 game, yeah? I'm basing that off you linking to the SG event page for the 04-03 game and that does appear to be missing from your output.

Pasted_Image_4_1_19__10_48_PM

I'm not sure why this isn't working for you. Have you tried taking the formed URL and viewing it in your browser to validate the event isn't there?

https://api.seatgeek.com/2/events?client_id={client_id}&performers[home_team].id=26&venue.city=Cincinnati&datetime_utc.gte=2019-03-28&datetime_utc.lte=2019-10-30&venue.city=Cincinnati&format=json&per_page=100

shows it for me (replace my {client_id} template with your client id)

BTW, you can make your request a little more specific and probably ever-so-slightly faster by changing venue.city=Cincinnati to venue.id=26:

https://api.seatgeek.com/2/events?client_id={client_id}&performers[home_team].id=26&venue.city=Cincinnati&datetime_utc.gte=2019-03-28&datetime_utc.lte=2019-10-30&venue.id=26&format=json&per_page=100

Finally, you don't need a client_secret for these requests.

gr33ngiant112 commented 5 years ago

@dallasgutauckis Correct, apologies. Absolute copy/paste fail 🤦‍♂️ Updated. Yes, the April 3rd game wasn't and still isn't showing from my API call. There are others I found to be missing earlier but didn't record them.

Thanks for the efficiency tips, will implement!

I do however 100% see it with the template you posted. Again, 🤦‍♂️ The Formatted output I posted is a dict I built by looping through each event, grabbing the title and datetime_local value so idk wtf I'm doing wrong. I get almost every other game but a few, the April 3rd one included.

    events = get_events(performer_id, endpoint, current_year, client_id, client_secret, proxies)
    # Build our new events dict
    schedule = {}
    for key, val in events.items():
        if key == "events":
            for event in val:
                schedule.update({event['title']:event['datetime_local']})   

Formatted output I pasted above is from the schedule{} dict.

gr33ngiant112 commented 5 years ago

Yeah, so I just grabbed the same request URL that my code builds:

https://api.seatgeek.com/2/events?client_id=<my_client_id>&performers%5Bhome_team%5D.id=26&datetime_utc.gte=2019-03-28&datetime_utc.lte=2019-10-30&venue.city=Cincinnati&per_page=100&format=json

When I click the link, I see

[1,11,22,31,17,16,32,0],"average_price":34,"lowest_price_good_deals":14,"median_price":27,"listing_count":130,"lowest_price":14,"highest_price":104},"title":"Milwaukee Brewers at Cincinnati Reds","announce_date":"2018-10-30T00:00:00","score":0.671,"access_method":{"employee_only":false,"created_at":"2017-04-05T15:06:32Z","method":"PDF417"},"announcements":{},"taxonomies":[{"name":"sports","parent_id":null,"id":1000000},{"name":"baseball","parent_id":1000000,"id":1010000},{"name":"mlb","parent_id":1010000,"id":1010100}],"type":"mlb","status":"normal","description":"","datetime_local":"2019-04-03

But when I build the schedule dict from the returned events, I'm losing the April 3rd game. 100% my code. I wonder if it has something to do with running it through the json builtin in the requests module.. got me thinking.

Will close the issue, looks to be my code.

thanks for you help and sorry to bother unnecessarily.

dallasgutauckis commented 5 years ago

No worries, hope you figure it out!