Beispiel #1
0
def scrape_espn_play_by_plays(withProgress, game_ids, start_yr):
    """
    Gets play by play data from ESPN API for the games who's ids are in game_ids
    Returns a list of json objects (containing play-by-plays for each game)
    """
    data = []
    for i, game_id in enumerate(game_ids):
        pbp_url = espn.get_game_url("playbyplay", league, game_id)
        pbp_json = espn.get_url(pbp_url,
                                cached_path=cached_json,
                                game_id=game_id)
        data.append(pbp_json)
    return data
Beispiel #2
0
# print nfl 2016 postseason scores
scoreboard_urls = espn.get_all_scoreboard_urls("nfl", 2017)
for scoreboard_url in scoreboard_urls:
    data = espn.get_url(scoreboard_url, cached_path="cached_json")
    for event in data['content']['sbData']['events']:
        if event['season']['type'] == 3:
            print(
                event['season']['type'], event['season']['year'],
                event['competitions'][0]['competitors'][0]['team']
                ['abbreviation'],
                event['competitions'][0]['competitors'][0]['score'],
                event['competitions'][0]['competitors'][1]['team']
                ['abbreviation'],
                event['competitions'][0]['competitors'][1]['score'])

url = espn.get_game_url("boxscore", "nba", 400900498)
json_data = espn.get_url(url)
print(json_data['gamepackageJSON']['boxscore']['teams'][0]['team']['name'])
ppjson(json_data['gamepackageJSON']['boxscore']['teams'][0]['statistics'][0])

url = espn.get_game_url("playbyplay", "ncf", 400868977)
json_data = espn.get_url(url)
print(
    json_data['gamepackageJSON']['drives']['previous'][0]['plays'][0]['text'])

# a few requests will return a beautiful soup objects instead of json
url = espn.get_game_url("boxscore", "nhl", 400885533)
soup = espn.get_url(url)
away_team = soup.select('.team-info a')[0].text
home_team = soup.select('.team-info a')[1].text
away_score = soup.select('.team-info .gp-awayScore')[0].text
Beispiel #3
0
 def test_nhl_boxscore(self):
     data = espn.get_url(espn.get_game_url("boxscore", "nhl", 400885533))
     away_score = int(data.select('.h2')[0].text.strip())
     home_score = int(data.select('.h2')[1].text.strip())
     self.assertEqual(away_score, 5)
     self.assertEqual(home_score, 1)
Beispiel #4
0
def boxscore_helper(self, league, espn_id):
    data = espn.get_url(espn.get_game_url("boxscore", league, espn_id))
    self.assertEqual(data['gameId'], espn_id)
Beispiel #5
0
 def test_wnba_boxscore(self):
     data = espn.get_url(espn.get_game_url("boxscore", "wnba", 400910431))
     away_score = int(data.select('.team-info span')[0].text.strip())
     home_score = int(data.select('.team-info span')[1].text.strip())
     self.assertEqual(away_score, 85)
     self.assertEqual(home_score, 94)
Beispiel #6
0
 def test_mlb_boxscore(self):
     data = espn.get_url(espn.get_game_url("boxscore", "mlb", 370328119))
     away_score = int(data.select('.team-info span')[0].text.strip())
     home_score = int(data.select('.team-info span')[1].text.strip())
     self.assertEqual(away_score, 1)
     self.assertEqual(home_score, 3)