-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show all winning teams for a season? #28
Comments
This does the trick for me: >>> import nflgame
>>> games = nflgame.games(2012, week=1)
>>> for g in games:
... print g.winner
...
...
DAL
CHI
MIN
NYJ
HOU
NE
DET
WAS
PHI
ATL
SF
ARI
TB
DEN
BAL
SD That's only for week 1, so you'll need to use Unfortunately, the |
import nflgame
games = nflgame.games(2010)
teams = {}
for game in games:
if game.winner not in teams:
teams[game.winner] = [1, 0]
else:
teams[game.winner][0] += 1
if game.loser not in teams:
teams[game.loser] = [0, 1]
else:
teams[game.loser][1] += 1
for team in teams:
print team, '%s-%s' % (teams[team][0], teams[team][1])
|
Sweet! Thanks all. |
@ochawkeye If you don't mind, I'm going to keep beating you over the head with data structures from the standard library! from collections import defaultdict
import nflgame
games = nflgame.games(2012)
wins, losses = defaultdict(int), defaultdict(int)
for game in games:
wins[game.winner] += 1
losses[game.loser] += 1
for team in (t[0] for t in nflgame.teams):
print team, '%d-%d' % (wins[team], losses[team]) This abuses the fact that |
Mind? You kidding me...This is the only place I ever get any feedback at
|
I'll just leave this here as a taste of things to come with nfldb:
|
Thanks for the help, guys. However, is it possible to use nflgame to loop over an entire season and return the winners by week? The only thing I see is gamekey Backstory: We're running a fantasy league of whole team owners that get points for wins each week. I'd like to run a script once per week to build out a json file of weekly winners and losers. I'll consume this json to output the standings. Thanks again! |
Hmm. I thought that was exactly what I gave you. If you give it a week number (in the >>> import nflgame
>>> games = nflgame.games(2012, week=1)
>>> for g in games:
... print g.winner, g.loser
...
...
DAL NYG
CHI IND
MIN JAC
NYJ BUF
HOU MIA
NE TEN
DET STL
WAS NO
PHI CLE
ATL KC
SF GB
ARI SEA
TB CAR
DEN PIT
BAL CIN
SD OAK If you want to do an entire season, then just get rid of the import nflgame
for week in range(1, 18):
games = nflgame.games(2012, week=week)
for g in games:
print week, g.winner, g.loser |
Yep, the week param. setting week var to a range was where I was getting stuck! I was trying to dig out week within the games list. I never thought of just using range. Thanks again, brother. This is awesome. |
👍 |
I can return the winning team if I specify the index of one of the objects, but not all winning from a season. (this api is awesome. thank you!)
The text was updated successfully, but these errors were encountered: