baseball/data.py

25 lines
525 B
Python

import requests
import os
ESPN_URL = str("https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard")
def get_game_data():
res = requests.get(ESPN_URL).json()
return res["events"]
def get_team_game(team, games):
found_team = None
for game in games:
competition = game["competitions"][0]
found_team = filter(lambda c: c.team.abbrevation.lower() == team,
competition["competitors"])
if found_team:
break
return found_team