Skip to content

Commit

Permalink
Port of master pull-request BurntSushi#328 (#14)
Browse files Browse the repository at this point in the history
* 22nd Annual Charles Leno Junior Memorial Award(TM)

* Cleanup nfl team list in __init__.py

Removed arbitary teams that included a dot between letters as alternate name.
Reordered SD and LAC teams so non-existant SD team quit overwriting LAC.

* Fix TypeError when reduce() is performed on an empty list

* _create_schedule demonstration
  • Loading branch information
ochawkeye authored and derek-adair committed Aug 23, 2018
1 parent f632d0a commit 7546675
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
27 changes: 15 additions & 12 deletions nflgame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,27 @@
['DAL', 'Dallas', 'Cowboys', 'Dallas Cowboys'],
['DEN', 'Denver', 'Broncos', 'Denver Broncos'],
['DET', 'Detroit', 'Lions', 'Detroit Lions'],
['GB', 'Green Bay', 'Packers', 'Green Bay Packers', 'G.B.', 'GNB'],
['GB', 'Green Bay', 'Packers', 'Green Bay Packers', 'GNB'],
['HOU', 'Houston', 'Texans', 'Houston Texans'],
['IND', 'Indianapolis', 'Colts', 'Indianapolis Colts'],
['JAC', 'Jacksonville', 'Jaguars', 'Jacksonville Jaguars', 'JAX'],
['KC', 'Kansas City', 'Chiefs', 'Kansas City Chiefs', 'K.C.', 'KAN'],
['LA', 'Los Angeles', 'Rams', 'Los Angeles Rams', 'L.A.'],
['KC', 'Kansas City', 'Chiefs', 'Kansas City Chiefs', 'KAN'],
['LA', 'Los Angeles', 'Rams', 'Los Angeles Rams', 'LAR'],
['SD', 'San Diego', 'Chargers', 'San Diego Chargers', 'SDG'],
['LAC', 'Los Angeles C', 'Chargers', 'Los Angeles Chargers', 'LAC'],
['MIA', 'Miami', 'Dolphins', 'Miami Dolphins'],
['MIN', 'Minnesota', 'Vikings', 'Minnesota Vikings'],
['NE', 'New England', 'Patriots', 'New England Patriots', 'N.E.', 'NWE'],
['NO', 'New Orleans', 'Saints', 'New Orleans Saints', 'N.O.', 'NOR'],
['NYG', 'Giants', 'New York Giants', 'N.Y.G.'],
['NYJ', 'Jets', 'New York Jets', 'N.Y.J.'],
['NE', 'New England', 'Patriots', 'New England Patriots', 'NWE'],
['NO', 'New Orleans', 'Saints', 'New Orleans Saints', 'NOR'],
['NYG', 'New York G', 'Giants', 'New York Giants'],
['NYJ', 'New York J', 'Jets', 'New York Jets'],
['OAK', 'Oakland', 'Raiders', 'Oakland Raiders'],
['PHI', 'Philadelphia', 'Eagles', 'Philadelphia Eagles'],
['PIT', 'Pittsburgh', 'Steelers', 'Pittsburgh Steelers'],
['SD', 'San Diego', 'Chargers', 'San Diego Chargers', 'S.D.', 'SDG'],
['SEA', 'Seattle', 'Seahawks', 'Seattle Seahawks'],
['SF', 'San Francisco', '49ers', 'San Francisco 49ers', 'S.F.', 'SFO'],
['STL', 'St. Louis', 'Rams', 'St. Louis Rams', 'S.T.L.'],
['TB', 'Tampa Bay', 'Buccaneers', 'Tampa Bay Buccaneers', 'T.B.', 'TAM'],
['SF', 'San Francisco', '49ers', 'San Francisco 49ers', 'SFO'],
['STL', 'St. Louis', 'Rams', 'St. Louis Rams'],
['TB', 'Tampa Bay', 'Buccaneers', 'Tampa Bay Buccaneers', 'TAM'],
['TEN', 'Tennessee', 'Titans', 'Tennessee Titans'],
['WAS', 'Washington', 'Redskins', 'Washington Redskins', 'WSH'],
]
Expand Down Expand Up @@ -176,7 +177,7 @@ def standard_team(team):
nflgame.teams (case insensitive). All known variants of a team name are
searched. If no team is found, None is returned.
"""
team = team.lower()
team = team.lower().replace('.', '')
for variants in teams:
for variant in variants:
if team == variant.lower():
Expand Down Expand Up @@ -370,6 +371,8 @@ def combine_play_stats(games):
N.B. Since this combines *all* play data, this function may take a while
to complete depending on the number of games passed in.
"""
if not games:
return []
return reduce(lambda p1, p2: p1 + p2,
[g.drives.players() for g in games if g is not None])

Expand Down
2 changes: 2 additions & 0 deletions nflgame/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def _create_schedule(jsonf=None):
dictionaries with the following keys: week, month, year, home,
away, wday, gamekey, season_type, time.
"""
print "...back again"
day = 60 * 60 * 24
if jsonf is None:
jsonf = _sched_json_file
Expand All @@ -41,6 +42,7 @@ def _create_schedule(jsonf=None):
last_updated = datetime.datetime.now()
return d, last_updated

print "Guess who's back..."
games, last_updated = _create_schedule()

__pdoc__['nflgame.sched.games'] = """
Expand Down
2 changes: 1 addition & 1 deletion nflgame/update_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def meta_from_soup_row(team, soup_row):
if ',' not in name:
last_name, first_name = name, ''
else:
last_name, first_name = map(lambda s: s.strip(), name.split(','))
last_name, first_name = map(lambda s: s.strip(), name.split(','))[:2]

return {
'team': team,
Expand Down

0 comments on commit 7546675

Please sign in to comment.