Skip to content

Instantly share code, notes, and snippets.

import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2016, week=6)
for game in q.as_games():
print game
print game.winner, game.loser
import nflgame
games = nflgame.games(year=2016, kind='REG')
for game in games:
print game
"""
CAR (20) at DEN (21)
TB (31) at ATL (24)
BUF (7) at BAL (13)
"""Display a chart of games that have and have not yet been played for a given week."""
import nflgame
def started_ticker(game):
print '{}\t{}\t\t{}'.format(game.away, game.score_away, game.time)
print '{}\t{}'.format(game.home, game.score_home)
print '-'*25
def unstarted_ticker(game):
@ochawkeye
ochawkeye / gist:8289332
Created January 6, 2014 20:29
nfldb-update error
c:\Python27\Scripts>python nfldb-update
-------------------------------------------------------------------------------
STARTING NFLDB UPDATE AT 2014-01-06 14:28:44.339000
Connecting to nfldb... done.
Setting timezone to UTC... done.
Updating player JSON database... (last update was 2014-01-04 03:55:54.395000+00:
00)
Loading games for POST 2013 week 19
Traceback (most recent call last):
File "c:\Python27\lib\runpy.py", line 162, in _run_module_as_main
@ochawkeye
ochawkeye / gist:8244268
Created January 3, 2014 19:05
PR, KR, and D
games = nflgame.games(year, week=week, kind=season_type)
kick_returns, punt_returns = [], []
plays = nflgame.combine_plays(games)
playsKR = plays.filter(kickret_ret__ge=1)
for player in playsKR.players():
kick_returns.append([
str(player)+', '+player.team,
player.kickret_ret,
player.kickret_yds,
player.kickret_tds])
@ochawkeye
ochawkeye / team_rosters.py
Last active November 24, 2015 21:50
Attempt at assembling rosters from past seasons
import nflgame
year = 2014
games = nflgame.games(year)
players = nflgame.combine(games)
positions = set([p.player.position for p in players if p.player.position])
# Sets up some empty dictionaries for each team to hold all of the positions
teams = nflgame.teams
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, season_type='Regular', team='NE',)
print len(q.as_drives())
q.drive(pos_team='NE')
print len(q.as_drives())
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
team = 'MIN'
def redzone(field):
cutoff = nfldb.FieldPosition.from_str(field)
return lambda play: play.yardline >= cutoff
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015)
q.player(full_name='Tom Brady')
q.play(offense_tds=1)
def redzone(field):
cutoff = nfldb.FieldPosition.from_str(field)
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, week=7, team='MIN')
def redzone(field):
cutoff = nfldb.FieldPosition.from_str(field)
return lambda play: play.yardline >= cutoff