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.27k stars 413 forks source link

nflgame searches by position #206

Open cphipps opened 8 years ago

cphipps commented 8 years ago

I am trying to find a way when searching for info to only include players at a certain position. For example if I am looking for receiving_yds and receiving_tds and I only want to see Tight Ends, not Wide Receivers or Running Backs. Just checking if there is anything built into nflgame that would allow me to do this?

Thanks

ochawkeye commented 8 years ago

Check out the .player.position attribute for your nflgame players.

import nflgame
games = nflgame.games(year=2015, week=1)
players = nflgame.combine(games)
for p in players.receiving().sort("receiving_yds").limit(15):
    print p, p.receiving_yds, p.player.position
K.Allen 166 WR
J.Jones 141 WR
A.Brown 133 WR
A.Seferian-Jenkins 110 TE
T.Kelce 106 TE
N.Washington 105 WR
T.Eifert 104 TE
J.Matthews 102 WR
K.Wright 101 WR
D.Hopkins 98 WR
M.Ingram 98 RB
J.Edelman 97 WR
R.Gronkowski 94 TE
T.Benjamin 89 WR
T.Hilton 88 WR
ochawkeye commented 8 years ago

A simple snippet to see receiving leaders for week 1 2015 separated by position.

import nflgame
games = nflgame.games(year=2015, week=1)
players = nflgame.combine(games)

for pos in ['WR', 'TE', 'RB']:
    for p in filter(lambda z: z.player.position==pos, players.receiving().sort("receiving_yds")):
        print p, p.receiving_yds, p.player.position
    print '-'*79
cphipps commented 8 years ago

Great, thank you.