BurntSushi / nflgame

An API to retrieve and read NFL Game Center JSON data. It can work with real-time data, which can be used for fantasy football.
http://pdoc.burntsushi.net/nflgame
The Unlicense
1.28k stars 413 forks source link

Filter by Opponent? #49

Closed front9tech closed 11 years ago

front9tech commented 11 years ago

Is it possible to filter by opponent played against? For example, I want to filter on all QBs that played against the Buffalo Bills.

BurntSushi commented 11 years ago

Absolutely! The key is to utilize the team field:

import nflgame

games = nflgame.games_gen(2013, home='BUF', away='BUF')
players = nflgame.combine_max_stats(games)

for p in players.filter(team__ne='BUF', passing_att__ge=1):
    print '%s, %d completions for %d yards and %d touchdowns.' \
          % (p.name, p.passing_cmp, p.passing_yds, p.passing_tds)

On my machine, this outputs:

[andrew@Liger nflgame] python2 buf-qb.py 
T.Brady, 29 completions for 288 yards and 2 touchdowns.
C.Newton, 21 completions for 229 yards and 2 touchdowns.
G.Smith, 16 completions for 331 yards and 2 touchdowns.
J.Flacco, 25 completions for 347 yards and 2 touchdowns.
B.Hoyer, 2 completions for 25 yards and 0 touchdowns.
B.Weeden, 13 completions for 197 yards and 1 touchdowns.
A.Dalton, 26 completions for 337 yards and 3 touchdowns.
front9tech commented 11 years ago

@BurntSushi thanks for the advice. I just started looking at this project and it is great.

Thanks for all the work you've put in. Once I get more familiar with nflgame I'd be happy to help in any way possible.

BurntSushi commented 11 years ago

@front9tech Thanks! The best way you can help is just be responding to help requests on the issue tracker, or hanging around the #nflgame IRC channel on the FreeNode server. :-)

(Or adding any cool things you've written to the wiki.)