derek-adair / nflgame

A working snapshot of nflgame (for historic purposes). This project is no longer active.
http://nflgame.derekadair.com
The Unlicense
331 stars 100 forks source link

Error in json #98

Closed 2Skupz closed 4 years ago

2Skupz commented 4 years ago

I have a little script that I use this for to find exciting NFL games to rewatch. Last weekend I started getting this error:

File "/home/ken/.local/lib/python3.6/site-packages/nflgame/init.py", line 224, in games return list(games_gen(year, week, home, away, kind, started)) File "/home/ken/.local/lib/python3.6/site-packages/nflgame/init.py", line 271, in gen g = nflgame.game.Game(**info) File "/home/ken/.local/lib/python3.6/site-packages/nflgame/game.py", line 315, in new game.data = json.loads(game.rawData.decode('utf-8'))[game.eid] AttributeError: 'NoneType' object has no attribute 'decode'

What can we do?

2Skupz commented 4 years ago

Further testing: This is limited to week 16 of the 2019 season. Week 15 works fine as do all previous seasons I've tested.

johnbartkiw commented 4 years ago

I haven't had time to dig into this but I just wanted to confirm that I can repro this problem as well.

ochawkeye commented 4 years ago

I had to '--rebuild' the nflgame schedule this week because two games ended up with the same eid. The two are likely related.

In your python scripts folder you should find this update schedule script. Run it with the --rebuild flag.

On Wed, Dec 25, 2019, 11:49 AM johnbart notifications@github.com wrote:

I haven't had time to dig into this but I just wanted to confirm that I can repro this problem as well.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/derek-adair/nflgame/issues/98?email_source=notifications&email_token=AAW3P3PHEL3GVWDXOUCBXZDQ2OMLFA5CNFSM4J7A3SY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHUQHGY#issuecomment-568918939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW3P3LQ6RZZLFGJUNOAX7LQ2OMLFANCNFSM4J7A3SYQ .

johnbartkiw commented 4 years ago

Can confirm this fixes things. Thanks! :)

ochawkeye commented 4 years ago

Apologies for cross pollinating, but if you do --rebuild your schedule, be warned that you will likely encounter some KeyError errors in nfldb. (Or maybe it was just coincidence this week with a number of flex games that moved).

I took care of this by simple deleting those games from the nfldb Postgres database.

import nfldb
db = nfldb.connect()

# q = nfldb.Query(db)
# q.game(season_year=2019, season_type='Regular', week=2)
# gsis_ids = [game.gsis_id for game in q.as_games()]
gsis_ids = ['2019122203', '2019122204']

for gsis_id in gsis_ids:
    query = "DELETE FROM game where gsis_id = '{}';".format(gsis_id)
    with nfldb.Tx(db) as cursor:
        cursor.execute(query)  
Coop197823 commented 4 years ago

I had to '--rebuild' the nflgame schedule this week because two games ended up with the same eid. The two are likely related. In your python scripts folder you should find this update schedule script. Run it with the --rebuild flag.

@ochawkeye as in issue #99, I was able to run: $ python nflgame-update-schedule --rebuild

however, the same issue still persists when I run the code below in python 3.7:

import nflgame
import sys
import csv

week = 16
games = nflgame.games(2019, week=week)

path3 = "C:\\Users\\Documents\\nfl\\Current2019\\WeeklyData\\Week"  + str(week)+".csv"
nflgame.nflgame.combine_max_stats(games).csv(path3)

I can confirm this code works fine for all other weeks (except week 16 in 2018) Any thoughts as to why this is still happening even after running the --rebuild?

ochawkeye commented 4 years ago

Just guessing here, but do you have separate nflgame libraries in both Python 2 & Python 3?

When you run python nflgame-update-schedule --rebuild is it affecting your Python 2 schedule.json but not your Python 3 version?

Coop197823 commented 4 years ago

@ochawkeye egg on my face, that was it. The 27 python was in front of the 37 in my environmental vars path.

The only other thing seems to be a large section of the positions are not populating for the week 16 2018. They are coming up blanks as opposed to being filled in. Would I need to do something through nflgame-update-palyers.py in order to fix those issues?

ocmolina commented 4 years ago

I had to '--rebuild' the nflgame schedule this week because two games ended up with the same eid. The two are likely related. In your python scripts folder you should find this update schedule script. Run it with the --rebuild flag. On Wed, Dec 25, 2019, 11:49 AM johnbart @.***> wrote: I haven't had time to dig into this but I just wanted to confirm that I can repro this problem as well. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#98?email_source=notifications&email_token=AAW3P3PHEL3GVWDXOUCBXZDQ2OMLFA5CNFSM4J7A3SY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHUQHGY#issuecomment-568918939>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW3P3LQ6RZZLFGJUNOAX7LQ2OMLFANCNFSM4J7A3SYQ .

Thanks!! actually I ran python3 update_sched.py --year=2019 && python3 update_sched.py --rebuild

derek-adair commented 4 years ago

I'll be pushing the updated player/schedule json shortly... HOPEFULLY today but the more i'm looking at all these bugs its clear I need to write some tests.