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

Unknown issue when printing #94

Closed claybuster closed 9 years ago

claybuster commented 10 years ago

No errors come up when I try to use my script that shows average points per game that worked last year. Burntsushi has updated the code to work with the new update but it still doesn't work. Note that my schedule is properly updated.

import nflgame
import nflgame.sched
import colorama
from colorama import init
from colorama import Fore, Back, Style
init()
schedule_games = nflgame.sched.games

for gsis_id, info in schedule_games.iteritems():
    y, t, w = info['year'], info['season_type'], info['week']
    h, a = info['home'], info['away']
    if y == 2014 and w == 1:
        print(Fore.GREEN + h + Fore.WHITE + ' VS. ' +
               Fore.BLUE + a + Fore.BLACK)

        team_home = h
        team_away = a

        home_game_scores_for = []
        away_game_scores_for = []
        home_game_scores_against = []
        away_game_scores_against = []

        # Get the games for the home and away teams for the season
        gameHOME = nflgame.games_gen(2014, home=team_home, away=team_home, kind='REG')
        gameAWAY = nflgame.games_gen(2014, home=team_away, away=team_away, kind='REG')

        # Iterate through the games
        for g in gameHOME:
            # If the home team was home, add the score_home to the points for list and the score_away to the points against list
            if g.home == team_home:
                        home_game_scores_for.append(g.score_home)
                        home_game_scores_against.append(g.score_away)
            # If the home team was away, add the score_away to the points for list and the score_home to the points against list
            else:
                        home_game_scores_for.append(g.score_away)
                        home_game_scores_against.append(g.score_home)

        for g in gameAWAY:
            # If the away team was home, add the score_home to the points for list and the score_away to the points against list
            if g.home == team_away:
                        away_game_scores_for.append(g.score_home)
                        away_game_scores_against.append(g.score_away)
            # If the away team was away, add the score_away to the points for list and the score_home to the points against list
            else:
                        away_game_scores_for.append(g.score_away)
                        away_game_scores_against.append(g.score_home)

          # Print our the sum of our values divided by the number of values. Cast to a float to get decimal points
        print Fore.WHITE, Back.MAGENTA, 'AVG. Points Scored', Back.BLACK, Fore.BLACK, Back.GREEN, team_home, sum(home_game_scores_for)/float(len(home_game_scores_for)), Fore.WHITE, Back.MAGENTA, "VS.", Back.BLUE, Fore.WHITE, team_away, sum(away_game_scores_for)/float(len(away_game_scores_for)), Back.BLACK, Fore.BLACK
        print Fore.WHITE, Back.CYAN, 'AVG. Points Allowed', Back.BLACK, Fore.BLACK, Back.GREEN, team_home, sum(home_game_scores_against)/float(len(home_game_scores_against)), Fore.WHITE, Back.CYAN, " VS.", Back.BLUE, Fore.WHITE, team_away, sum(away_game_scores_against)/float(len(away_game_scores_against)), Back.BLACK, Fore.WHITE
        print(Back.BLACK)
ochawkeye commented 10 years ago

Printed for me. Do you have the latest version of nflgame?

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Ben>p:

P:\>cd "Projects\Home Computer\Fantasy Football\2014"

P:\Projects\Home Computer\Fantasy Football\2014>python claybuster.py
Traceback (most recent call last):
  File "claybuster.py", line 3, in <module>
    import colorama
ImportError: No module named colorama

P:\Projects\Home Computer\Fantasy Football\2014>pip install colorama
Downloading/unpacking colorama
  Downloading colorama-0.3.2.tar.gz
  Running setup.py (path:c:\users\ben\appdata\local\temp\pip_build_Ben\colorama\setup.py) egg_info for package colorama

Installing collected packages: colorama
  Running setup.py install for colorama

Successfully installed colorama
Cleaning up...

P:\Projects\Home Computer\Fantasy Football\2014>python claybuster.py
NYJ VS. IND
  AVG. Points Scored    NYJ 19.0   VS.   IND 24.0
  AVG. Points Allowed    NYJ 14.0    VS.   IND 31.0

BAL VS. SF
  AVG. Points Scored    BAL 21.0   VS.   SF 28.0
  AVG. Points Allowed    BAL 14.5    VS.   SF 17.0

WAS VS. NE
  AVG. Points Scored    WAS 6.0   VS.   NE 20.0
  AVG. Points Allowed    WAS 17.0    VS.   NE 33.0

KC VS. CIN
  AVG. Points Scored    KC 10.0   VS.   CIN 23.0
  AVG. Points Allowed    KC 26.0    VS.   CIN 16.0

DEN VS. SEA
  AVG. Points Scored    DEN 31.0   VS.   SEA 36.0
  AVG. Points Allowed    DEN 24.0    VS.   SEA 16.0

SD VS. DAL
  AVG. Points Scored    SD 17.0   VS.   DAL 17.0
  AVG. Points Allowed    SD 18.0    VS.   DAL 28.0

ATL VS. MIA
  AVG. Points Scored    ATL 37.0   VS.   MIA 33.0
  AVG. Points Allowed    ATL 34.0    VS.   MIA 20.0

CAR VS. BUF
  AVG. Points Scored    CAR 20.0   VS.   BUF 23.0
  AVG. Points Allowed    CAR 14.0    VS.   BUF 20.0

JAC VS. TB
  AVG. Points Scored    JAC 17.0   VS.   TB 14.0
  AVG. Points Allowed    JAC 34.0    VS.   TB 20.0

CHI VS. PHI
  AVG. Points Scored    CHI 20.0   VS.   PHI 34.0
  AVG. Points Allowed    CHI 23.0    VS.   PHI 17.0

MIN VS. OAK
  AVG. Points Scored    MIN 34.0   VS.   OAK 14.0
  AVG. Points Allowed    MIN 6.0    VS.   OAK 19.0

STL VS. NO
  AVG. Points Scored    STL 6.0   VS.   NO 34.0
  AVG. Points Allowed    STL 34.0    VS.   NO 37.0

DET VS. CLE
  AVG. Points Scored    DET 35.0   VS.   CLE 27.0
  AVG. Points Allowed    DET 14.0    VS.   CLE 30.0

NYG VS. PIT
  AVG. Points Scored    NYG 14.0   VS.   PIT 18.0
  AVG. Points Allowed    NYG 35.0    VS.   PIT 26.5

TEN VS. GB
  AVG. Points Scored    TEN 26.0   VS.   GB 16.0
  AVG. Points Allowed    TEN 10.0    VS.   GB 36.0

ARI VS. HOU
  AVG. Points Scored    ARI 18.0   VS.   HOU 17.0
  AVG. Points Allowed    ARI 17.0    VS.   HOU 6.0

SEA VS. GB
  AVG. Points Scored    SEA 36.0   VS.   GB 16.0
  AVG. Points Allowed    SEA 16.0    VS.   GB 36.0

ATL VS. NO
  AVG. Points Scored    ATL 37.0   VS.   NO 34.0
  AVG. Points Allowed    ATL 34.0    VS.   NO 37.0

BAL VS. CIN
  AVG. Points Scored    BAL 21.0   VS.   CIN 23.0
  AVG. Points Allowed    BAL 14.5    VS.   CIN 16.0

CHI VS. BUF
  AVG. Points Scored    CHI 20.0   VS.   BUF 23.0
  AVG. Points Allowed    CHI 23.0    VS.   BUF 20.0

HOU VS. WAS
  AVG. Points Scored    HOU 17.0   VS.   WAS 6.0
  AVG. Points Allowed    HOU 6.0    VS.   WAS 17.0

KC VS. TEN
  AVG. Points Scored    KC 10.0   VS.   TEN 26.0
  AVG. Points Allowed    KC 26.0    VS.   TEN 10.0

MIA VS. NE
  AVG. Points Scored    MIA 33.0   VS.   NE 20.0
  AVG. Points Allowed    MIA 20.0    VS.   NE 33.0

NYJ VS. OAK
  AVG. Points Scored    NYJ 19.0   VS.   OAK 14.0
  AVG. Points Allowed    NYJ 14.0    VS.   OAK 19.0

PHI VS. JAC
  AVG. Points Scored    PHI 34.0   VS.   JAC 17.0
  AVG. Points Allowed    PHI 17.0    VS.   JAC 34.0

PIT VS. CLE
  AVG. Points Scored    PIT 18.0   VS.   CLE 27.0
  AVG. Points Allowed    PIT 26.5    VS.   CLE 30.0

STL VS. MIN
  AVG. Points Scored    STL 6.0   VS.   MIN 34.0
  AVG. Points Allowed    STL 34.0    VS.   MIN 6.0

DAL VS. SF
  AVG. Points Scored    DAL 17.0   VS.   SF 28.0
  AVG. Points Allowed    DAL 28.0    VS.   SF 17.0

TB VS. CAR
  AVG. Points Scored    TB 14.0   VS.   CAR 20.0
  AVG. Points Allowed    TB 20.0    VS.   CAR 14.0

DEN VS. IND
  AVG. Points Scored    DEN 31.0   VS.   IND 24.0
  AVG. Points Allowed    DEN 24.0    VS.   IND 31.0

DET VS. NYG
  AVG. Points Scored    DET 35.0   VS.   NYG 14.0
  AVG. Points Allowed    DET 14.0    VS.   NYG 35.0

ARI VS. SD
  AVG. Points Scored    ARI 18.0   VS.   SD 17.0
  AVG. Points Allowed    ARI 17.0    VS.   SD 18.0

P:\Projects\Home Computer\Fantasy Football\2014>
ochawkeye commented 10 years ago

Still having an issue here @claybuster ?

BurntSushi commented 9 years ago

Closing due to inactivity from OP.