def test_roster_class_string_representation(self, *args, **kwargs): expected = """José Altuve (altuvjo01) Justin Verlander (verlaju01) José Altuve (mortoch02)""" flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return('2018') roster = Roster('HOU') assert roster.__repr__() == expected
def add_pitchers(apps, schema_editor): Player = apps.get_model('core', 'Player') summary_list = [] for x in range(1990, 1995): season = str(x) braves = Roster('ATL', season) pitchers = [ player for player in braves.players if player.position == 'P' ] for pitcher in pitchers: summary_list.append((pitcher.name, season, pitcher.position, pitcher(season).games, pitcher(season).era, pitcher(season).wins, pitcher(season).whip)) summary = tuple(summary_list) Player.objects.bulk_create( Player(name=name, season=season, position=position, games=games, era=era, wins=wins, whip=whip) for name, season, position, games, era, wins, whip in summary)
def add_pitchers(apps, schema_editor): Player = apps.get_model('core', 'Player') braves = Roster('ATL', '1995') pitchers = [player for player in braves.players if player.position == 'P'] for player in Player.objects.all(): player.name = pitcher.name player.save()
def test_roster_class_pulls_all_player_stats(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return('2017') roster = Roster('HOU') assert len(roster.players) == 3 for player in roster.players: assert player.name in [u'José Altuve', 'Justin Verlander', 'Charlie Morton']
def test_roster_class_with_slim_parameter(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return('2018') roster = Roster('HOU', slim=True) assert len(roster.players) == 3 assert roster.players == { 'altuvjo01': 'Jose Altuve', 'verlaju01': 'Justin Verlander', 'mortoch02': 'Charlie Morton' }
def add_pitchers(apps, schema_editor): Player = apps.get_model('core', 'Player') braves = Roster('ATL', '1995') pitchers = [player for player in braves.players if player.position == 'P'] summary_list = [] for pitcher in pitchers: summary_list.append((pitcher.name)) summary = tuple(summary_list) Player.objects.bulk_create(Player(name=name) for name in summary)
def test_mlb_invalid_default_year_reverts_to_previous_year(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return(2018) roster = Roster('HOU') assert len(roster.players) == 3 for player in roster.players: assert player.name in [u'José Altuve', 'Justin Verlander', 'Charlie Morton']
def test_bad_url_raises_value_error(self, *args, **kwargs): with pytest.raises(ValueError): roster = Roster('bad')
def test_coach(self): assert "AJ Hinch" == Roster('HOU', year=YEAR).coach
#!/usr/bin/python3 from sportsreference.nba.teams import Teams teams = Teams() for team in teams: print(team.name, team.abbreviation) print("-------------------------------") from datetime import datetime from sportsreference.mlb.boxscore import Boxscores games_today = Boxscores(datetime.today()) print(games_today.games) # Prints a dictionary of all matchups for today print("-------------------------------------") from sportsreference.mlb.roster import Roster dodgers = Roster('LAD') for player in dodgers.players: # Prints the name of all players who played for the Dodgers in the most # recent season. print(player.name)