robhowley / nhlscrapi

Python based web scraper API for NHL game data
Apache License 2.0
69 stars 28 forks source link

Index out of range - descparser.py #9

Closed brianmxwll closed 8 years ago

brianmxwll commented 8 years ago

Using the example code from the main "Usage Example" with the following info:

season = 2016
game_num = 49
game_type = GameType.Regular

Trigger parsing by accessing the plays:

game.plays

The code will throw an exception, redacted traceback:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\nhlscrapi\games\game.py", line 197, in plays
    return self.play_by_play.plays
  File "C:\Python27\lib\site-packages\nhlscrapi\games\playbyplay.py", line 81, in plays
    self.compute_stats()
  File "C:\Python27\lib\site-packages\nhlscrapi\games\playbyplay.py", line 95, in compute_stats
    for play in self._rep_reader.parse_plays_stream():
  File "C:\Python27\lib\site-packages\nhlscrapi\scrapr\rtss.py", line 56, in parse_plays_stream
    p_obj = parser.build_play(p)
  File "C:\Python27\lib\site-packages\nhlscrapi\scrapr\rtss.py", line 140, in build_play
    parse_event_desc(p['event'], season=self.season)
  File "C:\Python27\lib\site-packages\nhlscrapi\scrapr\eventparser.py", line 75, in parse_event_desc
    dp.parse_block_08(event)
  File "C:\Python27\lib\site-packages\nhlscrapi\scrapr\descparser.py", line 245, in parse_block_08
    event.zone = s[2]

Defect is caused by parsing the following play description:

ARI #26 STONE BLOCKED BY  ANA #46 SEKAC, Off. Zone

The problem is that the shot type is missing - so when the following value is split by commas, there is an incorrect number of values.

'ANA #46 SEKAC, Off. Zone' -> ['ANA #46 SEKAC', 'Off. Zone']

Where the code expects the following index values: 0 = the player, 1 = shot type, 2 = zone.

The source of the data is here, CTRL+F for "303" to see the relevant line.

I'm still relatively new to the library so I'm not sure what the appropriate action is here - whether to use a default (blank) value or to just throw out the play. Deferring to your judgement.