def display_players(my_year): while 1: name = input("Team Name (l/list/q/quit/stop): ") name = name.upper() if (name == "") or (name == "Q") or (name == "QUIT") or (name == "STOP"): break if (name == "L") or (name == "LIST"): list_team_names(my_year) continue print("Getting Roster for %s, year %s" % (name, my_year)) # only get roster is not same as last one try: roster = Roster(name, year=my_year) lastAbbrevName = name except: print( "Unknown Team Name Abbreviations, use list to display Team and Abbreviations" ) continue for player in roster.players: print("Name: %-30s Weight: %-4s Height: %-3s" % (player.name, player.weight, player.height))
def test_roster_class_pulls_all_player_stats(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return('2018') roster = Roster('NOR') assert len(roster.players) == 5 for player in roster.players: assert player.name in ['Drew Brees', 'Demario Davis', 'Tommylee Lewis', 'Wil Lutz', 'Thomas Morstead']
def test_roster_class_with_slim_parameter(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return('2018') roster = Roster('NOR', slim=True) assert len(roster.players) == 5 assert roster.players == { 'BreeDr00': 'Drew Brees', 'DaviDe00': 'Demario Davis', 'LewiTo00': 'Tommylee Lewis', 'LutzWi00': 'Wil Lutz', 'MorsTh00': 'Thomas Morstead' }
def test_invalid_default_year_reverts_to_previous_year(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return(2019) roster = Roster('NOR') assert len(roster.players) == 5 for player in roster.players: assert player.name in ['Drew Brees', 'Demario Davis', 'Tommylee Lewis', 'Wil Lutz', 'Thomas Morstead']
def get_player_ids(): directory = './data/year/' years = os.listdir(directory) player_list = {} for year in years: teams = os.listdir('{0}/{1}'.format(directory, year)) for team in teams: roster = Roster(team, year=year) for player in roster.players: if player.player_id not in player_list: player_list[player.player_id] = player.name print('.', end=' ') print('{0} completed.'.format(year)) with open('./data/player_ids.json', 'w+') as outfile: json.dump(player_list, outfile)
def test_bad_url_raises_value_error(self, *args, **kwargs): with pytest.raises(ValueError): roster = Roster('BAD')
def run_hangman_game(year): lastAbbrevName = "" while 1: name = input("Team Name (l/list/q/quit/stop): ") name = name.upper() if (name == "") or (name == "Q") or (name == "QUIT") or (name == "STOP"): break if (name == "L") or (name == "LIST"): list_team_names(year) continue print("Getting Roster for %s, year %s" % (name, year)) # only get roster is not same as last one if lastAbbrevName != name: try: roster = Roster(name, year=year) lastAbbrevName = name except: print( "Unknown Team Name Abbreviations, use list to display Team and Abbreviations" ) continue numPlayers = len(roster.players) print("Ready to start guessing Players name len=%d ..." % numPlayers) # generate a random number between 0 and the number of players on the roster-1 index = random.randint(0, numPlayers - 1) #here we set the secret player = roster.players[index] #creates an variable with an single value of space ' ' guesses = ' ' name = player.name # print("name is: %s index is: %d" % (name, index)) misses = 0 maxMisses = 5 badGuesses = '' while misses < maxMisses: unknownLetters = 0 # for every character in secret_name for char in name.lower(): # see if the character is in the players guess if char in guesses: print(char, end=" ") else: print("_", end=" ") unknownLetters += 1 print("(badGuesses: %s)" % badGuesses) if unknownLetters == 0: print() print("Correct ... with %d misses! " % misses) break guess = input("guess a letter: ").lower() guesses += guess if guess not in name.lower(): badGuesses += guess.lower() misses = misses + 1 print("Wrong") print("You have %d misses out of %d" % (misses, maxMisses)) if misses == maxMisses: print("You Lose, name was: %s" % name.lower())
teams = Teams() for team in teams: team_array.append(team.abbreviation) print(team_array) # In[4]: player_array = [] tm_n = len(team_array) for yr in range (2008, 2019): for i in range(tm_n): try: roster = Roster(team_array[i], yr) print(team_array[i], str(yr)) for player in roster.players: player_array.append(player.player_id) except: print(team_array[i] + "does not exist " + str(yr)) # In[8]: final_player_array = np.unique(player_array) np.savetxt('player_array1', final_player_array, fmt='%5s', delimiter=',') # In[89]:
from sportsreference.nfl.roster import Roster import matplotlib.pyplot as plt from wordcloud import WordCloud, STOPWORDS import numpy as np from PIL import Image import random #Create empty list to store players names players = [] # Pull down 49ers roster from sportsrefence API - Reference: https://sportsreference.readthedocs.io/en/latest/nfl.html niners = Roster('SFO') #Loop through players and parse for their last names and add to the list for player in niners.players: if player.name != None: full_names = player.name last_names = full_names.split()[1] players.append(last_names) #Add the picture logo = np.array(Image.open("niners.png")) #Shuffle players names so the wordcloud uses other names beside alphabetically random.shuffle(players) #Create wordcloud wordcloud = WordCloud( width=2000, height=2000, background_color="red",
def test_coach(self): assert "Sean Payton" == Roster('NOR', year=YEAR).coach