Skip to content

Commit

Permalink
Trying to get #68 to work
Browse files Browse the repository at this point in the history
- _search_schedule by eid
- _search_schedule doesn't require year param now
- IF the gamecenter data isn't available...
   * Check to see if the schedule data was in the kwargs
   * If not > search for the data by EID.
  • Loading branch information
derek-adair committed Sep 26, 2019
1 parent 8c78e6a commit 072e387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nflgame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def combine_plays(games):
return nflgame.seq.GenPlays(chain)


def _search_schedule(year, week=None, home=None, away=None, kind='REG',
started=False):
def _search_schedule(year=None, week=None, home=None, away=None, kind='REG',
started=False, eid=None):
"""
Searches the schedule to find the game identifiers matching the criteria
given.
Expand Down Expand Up @@ -434,6 +434,8 @@ def _search_schedule(year, week=None, home=None, away=None, kind='REG',
for info in nflgame.sched.games.values():
y, t, w = info['year'], info['season_type'], info['week']
h, a = info['home'], info['away']
if eid is not None and eid != info['eid']:
continue
if year is not None:
if isinstance(year, list) and y not in year:
continue
Expand All @@ -459,5 +461,6 @@ def _search_schedule(year, week=None, home=None, away=None, kind='REG',
now = nflgame.live._now()
if gametime > now and (gametime - now).total_seconds() > 300:
continue

infos.append(info)
return infos
11 changes: 11 additions & 0 deletions nflgame/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ def __new__(cls, eid=None, fpath=None, **kwargs):
return None
if rawData is None or rawData.strip() == '{}':
gameData = dict()

# find the schedule data if it wasn't supplied in the kwargs
if len(kwargs) == 0 and eid is not None:
kwargs = nflgame._search_schedule(eid=eid)

if len(kwargs) == 0:
return None

# Flatten the search results
kwargs = kwargs[0]

gameData = {
'home': {
'abbr': kwargs['home'],
Expand Down

0 comments on commit 072e387

Please sign in to comment.