Home > Software engineering >  Is there a way to find five previous games with MLB-StatsAPI?
Is there a way to find five previous games with MLB-StatsAPI?

Time:09-27

For those who are familiar with MLB-StatsAPI in Python, I am looking for a way to find the previous five games a team has played. I have tried using statsai.schedule, but it will not work for what I am trying to do.

CodePudding user response:

Try this -

import statsapi

sched = statsapi.schedule(start_date='07/01/2018',end_date='07/31/2018',team=143)

newlist = sorted(sched, key = lambda k: k["game_date"], reverse=True)

for game in newlist[0:5]:
    print(game['game_date'] " : "  str(game['game_id']))
  • Related