From 7546675f38d60ddc4f7692b37326950915fd4fd7 Mon Sep 17 00:00:00 2001 From: ochawkeye Date: Thu, 23 Aug 2018 10:14:07 -0500 Subject: [PATCH] Port of master pull-request #328 (#14) * 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 --- nflgame/__init__.py | 27 +++++++++++++++------------ nflgame/sched.py | 2 ++ nflgame/update_players.py | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/nflgame/__init__.py b/nflgame/__init__.py index d7278188..2e344eaf 100644 --- a/nflgame/__init__.py +++ b/nflgame/__init__.py @@ -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'], ] @@ -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(): @@ -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]) diff --git a/nflgame/sched.py b/nflgame/sched.py index e653d9ab..a8bbbb43 100644 --- a/nflgame/sched.py +++ b/nflgame/sched.py @@ -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 @@ -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'] = """ diff --git a/nflgame/update_players.py b/nflgame/update_players.py index 7a9dec79..4b36ad57 100644 --- a/nflgame/update_players.py +++ b/nflgame/update_players.py @@ -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,