def current_games(year=None, week=None, kind='REG'): """ Returns a list of game.Games of games that are currently playing. If either year or week is none, then the current year and week are calculated. If they are *both* provided, then the provided values are used. So for example: year, week = nflgame.live.current_year_and_week() while True: games = nflgame.live.current_games(year, week) # Do something with games time.sleep(60) NOTE: Providing both year and week was originally mainly a way to prevent unnecessary calls to NFL.com. Now NFL.com is not called in current_year_and_week() anyway. Some (pretty slim) calculation time would still be saved, though. The kind parameter specifies whether to fetch preseason, regular season or postseason games. Valid values are PRE, REG and POST. """ if year is None or week is None: year, week = current_year_and_week() guesses = [] now = _now() games = _games_in_week(year, week, kind=kind) for info in games: gametime = _game_datetime(info) if gametime >= now: if (gametime - now).total_seconds() <= 60 * 15: guesses.append(info['eid']) elif (now - gametime).total_seconds() <= _MAX_GAME_TIME: guesses.append(info['eid']) # Now we have a list of all games that are currently playing, are # about to start in less than 15 minutes or have already been playing # for _MAX_GAME_TIME (6 hours?). Now fetch data for each of them and # rule out games in the last two categories. current = [] for guess in guesses: game = nflgame.game.Game(guess) if game is not None and game.playing(): current.append(game) return current
def current_games(year=None, week=None, kind='REG'): """ Returns a list of game.Games of games that are currently playing. If either year or week is none, then the current year and week are calculated. If they are *both* provided, then the provided values are used. So for example: year, week = nflgame.live.current_year_and_week() while True: games = nflgame.live.current_games(year, week) # Do something with games time.sleep(60) NOTE: Providing both year and week was originally mainly a way to prevent unnecessary calls to NFL.com. Now NFL.com is not called in current_year_and_week() anyway. Some (pretty slim) calculation time would still be saved, though. The kind parameter specifies whether to fetch preseason, regular season or postseason games. Valid values are PRE, REG and POST. """ if year is None or week is None: year, week = current_year_and_week() guesses = [] now = _now() games = _games_in_week(year, week, kind=kind) for info in games: gametime = _game_datetime(info) if gametime >= now: if (gametime - now).total_seconds() <= 60 * 15: guesses.append(info['eid']) elif (now - gametime).total_seconds() <= _MAX_GAME_TIME: guesses.append(info['eid']) # Now we have a list of all games that are currently playing, are # about to start in less than 15 minutes or have already been playing # for _MAX_GAME_TIME (6 hours?). Now fetch data for each of them and # rule out games in the last two categories. current = [] for guess in guesses: game = nflgame.game.Game(guess) if game is not None and game.playing(): current.append(game) return current
def current_games(year=None, week=None, kind='REG'): """ Returns a list of game.Games of games that are currently playing. This fetches all current information from NFL.com. If either year or week is none, then the current year and week are fetched from the schedule on NFL.com. If they are *both* provided, then the schedule from NFL.com won't need to be downloaded, and thus saving time. So for example:: year, week = nflgame.live.current_year_and_week() while True: games = nflgame.live.current_games(year, week) # Do something with games time.sleep(60) The kind parameter specifies whether to fetch preseason, regular season or postseason games. Valid values are PRE, REG and POST. """ if year is None or week is None: year, week = current_year_and_week() guesses = [] now = _now() games = _games_in_week(year, week, kind=kind) for info in games: gametime = _game_datetime(info) if gametime >= now: if (gametime - now).total_seconds() <= 60 * 15: guesses.append(info['eid']) elif (now - gametime).total_seconds() <= _MAX_GAME_TIME: guesses.append(info['eid']) # Now we have a list of all games that are currently playing, are # about to start in less than 15 minutes or have already been playing # for _MAX_GAME_TIME (6 hours?). Now fetch data for each of them and # rule out games in the last two categories. current = [] for guess in guesses: game = nflgame.game.Game(guess) if game is not None and game.playing(): current.append(game) return current
def current_games(year=None, week=None, kind='REG'): """ Returns a list of game.Games of games that are currently playing. This fetches all current information from NFL.com. If either year or week is none, then the current year and week are fetched from the schedule on NFL.com. If they are *both* provided, then the schedule from NFL.com won't need to be downloaded, and thus saving time. So for example:: year, week = nflgame.live.current_year_and_week() while True: games = nflgame.live.current_games(year, week) # Do something with games time.sleep(60) The kind parameter specifies whether to fetch preseason, regular season or postseason games. Valid values are PRE, REG and POST. """ if year is None or week is None: year, week = current_year_and_week() guesses = [] now = _now() games = _games_in_week(year, week, kind=kind) for info in games: gametime = _game_datetime(info) if gametime >= now: if (gametime - now).total_seconds() <= 60 * 15: guesses.append(info['eid']) elif (now - gametime).total_seconds() <= _MAX_GAME_TIME: guesses.append(info['eid']) # Now we have a list of all games that are currently playing, are # about to start in less than 15 minutes or have already been playing # for _MAX_GAME_TIME (6 hours?). Now fetch data for each of them and # rule out games in the last two categories. current = [] for guess in guesses: game = nflgame.game.Game(guess) if game is not None and game.playing(): current.append(game) return current
def current_games(year=None, week=None, kind=_cur_season_phase): """ Returns a list of game.Games of games that are currently playing. If either year or week is none, then the current year and week are calculated. If they are *both* provided, then the provided values are used. So for example: year, week = nflgame.live.current_year_and_week() while True: games = nflgame.live.current_games(year, week) # Do something with games time.sleep(60) """ if year is None or week is None: year, week = current_year_and_week() guesses = [] now = _now() games = _games_in_week(year, week, kind=kind) for info in games: gametime = _game_datetime(info) if gametime >= now: if (gametime - now).total_seconds() <= 60 * 15: guesses.append(info['eid']) elif (now - gametime).total_seconds() <= _MAX_GAME_TIME: guesses.append(info['eid']) # Now we have a list of all games that are currently playing, are # about to start in less than 15 minutes or have already been playing # for _MAX_GAME_TIME (6 hours?). Now fetch data for each of them and # rule out games in the last two categories. current = [] for guess in guesses: game = nflgame.game.Game(guess) if game is not None and game.playing(): current.append(game) return current