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

Error in update_players (ValueError: too many values to unpack) #265

Open guga31bb opened 8 years ago

guga31bb commented 8 years ago

import nflgame.update_players nflgame.update_players.run()


"C:\Program Files (x86)\python\python.exe" C:/Users/Ben/Dropbox/projects/nflscraping/success_rate.py Loading games for REG 2016 week 11 Finding (profile id -> gsis id) mapping for players... 2/2 complete. (100.00%) Done! Downloading team rosters... 32/32 complete. (100.00%) Done! Fetching GSIS identifiers for players not in nflgame... 41/41 complete. (100.00%) Done!

There were some errors during the download. Usually this is a result of an HTTP request timing out, which means the resulting "players.json" file is probably missing some data. An appropriate solution is to re-run the script until there are no more errors (or when the errors are problems on NFL.com side.)

Could not get profile URL for (00-0033021, J.Lampman)

Could not get profile URL for (00-0031363, M.Palardy)

Could not get player info from roster row:

72 Leno, Charles, Jr. T ACT 6'3" 305 10/9/1991 3 Boise State

Exception:

Traceback (most recent call last): File "C:\Program Files (x86)\python\lib\site-packages\nflgame\update_players.py", line 419, in run roster.append(meta_from_soup_row(team, row)) File "C:\Program Files (x86)\python\lib\site-packages\nflgame\update_players.py", line 179, in meta_from_soup_row last_name, first_name = map(lambda s: s.strip(), name.split(',')) ValueError: too many values to unpack

MichaelSnowden commented 8 years ago

I got the same error when I ran nfldb-update (also for the player from Boise State). Now, whenever I run nfldb-update, I get this:

$ nfldb-update 
-------------------------------------------------------------------------------
STARTING NFLDB UPDATE AT 2016-11-18 23:08:19.671340
Connecting to nfldb... done.
Setting timezone to UTC... done.
Locking write access to tables... done.
Updating season phase, year and week... done.
Bulk inserting data for 149 games...
    Sending batch of data to database.
    Sending batch of data to database.
    Sending batch of data to database.
    Sending batch of data to database.
    Sending batch of data to database.
    Sending batch of data to database.
    Sending batch of data to database.
Traceback (most recent call last):
  File "/usr/local/bin/nfldb-update", line 39, in <module>
    nfldb.update.run(**vars(args))
  File "/usr/local/lib/python2.7/site-packages/nfldb/update.py", line 535, in run
    doit()
  File "/usr/local/lib/python2.7/site-packages/nfldb/update.py", line 525, in doit
    update_games(db, batch_size=batch_size)
  File "/usr/local/lib/python2.7/site-packages/nfldb/update.py", line 397, in update_games
    bulk_insert_game_data(cursor, scheduled, batch_size=batch_size)
  File "/usr/local/lib/python2.7/site-packages/nfldb/update.py", line 195, in bulk_insert_game_data
    do()
  File "/usr/local/lib/python2.7/site-packages/nfldb/update.py", line 188, in do
    nfldb.db._big_insert(cursor, table, bulk[table])
  File "/usr/local/lib/python2.7/site-packages/nfldb/db.py", line 356, in _big_insert
    % (table, insert_fields, values))
  File "/usr/local/lib/python2.7/site-packages/psycopg2/extras.py", line 223, in execute
    return super(RealDictCursor, self).execute(query, vars)
psycopg2.IntegrityError: insert or update on table "play" violates foreign key constraint "play_pos_team_fkey"
DETAIL:  Key (pos_team)=(JAX) is not present in table "team".

Some info:

  1. macOS Sierra 10.12.1
  2. Just installed nflgame and nfldb today
  3. Running Python 2.7

EDIT: This appears to be because we are unpacking the player's first and last name just using a comma separator, but the player's name is being unpacked as [u'Leno', u' Charles', u' Jr.'], which has 3 values. I think the fix here would be to consider everything before the first comma as the last name, and everything after that as the first name. I.e. I'd change this line (179 in update_players.py) from

last_name, first_name = map(lambda s: s.strip(), name.split(',')) to this

last_name, first_name = map(lambda s: s.strip(), name.split(',')[:2])

I can confirm that this resolves the issue.