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

Player Game Information #247

Open bhavik3jain opened 8 years ago

bhavik3jain commented 8 years ago

I am new to this API and I was just wondering if there was a way to get the game information of a specific player. I know I can get all the statistics for the player but can I get the team this player played against?

ochawkeye commented 8 years ago

Sure. There are probably other ways, but a player's .home attribute will tell you if he was on the home team.

import nflgame
games = nflgame.games(year=2016, week=5, kind='REG')

for game in games:
    for player in game.players:
        print '{} ({}) played against {}'.format(player, player.team, game.away if player.home else game.home)
B.Gabbert (SF) played against ARI
...
J.Witten (DAL) played against CIN
...
J.Winston (TB) played against CAR