nhlscrapi.scrapr package¶
Submodules¶
nhlscrapi.scrapr.nhlreq module¶
-
class
nhlscrapi.scrapr.nhlreq.NHLCn[source]¶ Bases:
objectBuilds the URLs, makes the HTTP calls and retreives the raw HTML associated with various NHL report data. If an error occurs in the retrieval process, the error is recorded in
req_err.-
event_summary(game_key)[source]¶ Returns: raw HTML for the event summary report (ES) Return type: string
-
html_src= None¶ The HTML source of the last NHL page requested.
-
req_err= None¶ Error from the last HTTP request.
-
nhlscrapi.scrapr.reportloader module¶
-
class
nhlscrapi.scrapr.reportloader.ReportLoader(game_key, report_type='')[source]¶ Bases:
objectBase class for objects that load full reports. Manages html request and extracts match up from banner
Parameters: - game_key – unique game identifier of type
nhlscrapi.games.game.GameKey - report_type – str, type of report being loaded. Must be a method of
NHLCn
-
game_key= None¶ Game key being retrieved of type
nhlscrapi.games.game.GameKey
-
html_doc()[source]¶ Returns: the lxml processed html document Return type: lxml.html.document_fromstringoutput
-
matchup= None¶ Fame meta information displayed in report banners including team names, final score, game date, location, and attendance. Data format is
{ 'home': home, 'away': away, 'final': final, 'attendance': att, 'date': date, 'location': loc }
-
parse_matchup()[source]¶ Parse the banner matchup meta info for the game.
Returns: selfon success orNone
-
req_err= None¶ Error from http request
- game_key – unique game identifier of type
nhlscrapi.scrapr.rtss module¶
-
class
nhlscrapi.scrapr.rtss.PlayParser(season=2015)[source]¶ Bases:
objectInterprets a single RTSS play by play table row, i.e. a single play. Constructs a dictionary of play features.
-
static
ColMap(season)[source]¶ Returns a dictionary mapping the type of information in the RTSS play row to the appropriate column number. The column locations pre/post 2008 are different.
Parameters: season – int for the season number Returns: mapping of RTSS column to info type Return type: dict, keys are 'play_num', 'per', 'str', 'time', 'event', 'desc', 'vis', 'home'
-
build_play(pbp_row)[source]¶ Parses table row from RTSS. These are the rows tagged with
<tr class='evenColor' ... >. Result set containsnhlscrapi.games.playbyplay.Strengthandnhlscrapi.games.events.EventTypeobjects. Returned play data is in the form{ 'play_num': num_of_play 'period': curr_period 'strength': strength_enum 'time': { 'min': min, 'sec': sec } 'vis_on_ice': { 'player_num': player } 'home_on_ice': { 'player_num': player } 'event': event_object }Parameters: pbp_row – table row from RTSS Returns: play data Return type: dict
-
static
-
class
nhlscrapi.scrapr.rtss.RTSS(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load RTSS play by play game data
-
parse_plays()[source]¶ Retreive and parse Play by Play data for the given
nhlscrapi.games.GameKeyReturns: selfon success,Noneotherwise
-
parse_plays_stream()[source]¶ Generate and yield a stream of parsed plays. Useful for per play processing.
-
plays= None¶ List of plays loaded. See
PlayParserfor play data structure.
-
nhlscrapi.scrapr.rosterrep module¶
-
class
nhlscrapi.scrapr.rosterrep.RosterRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load roster report from nhl.com. This is a base class and not intended to be used directly.
-
coaches= None¶ Dictionary of coaches keyed home/away loaded
-
officials= None¶ Game officials:
{ 'refs': { }, 'linesman': { } }
-
parse()[source]¶ Retreive and parse Play by Play data for the given
nhlscrapi.games.game.GameKey`Returns: selfon success,Noneotherwise
-
parse_rosters()[source]¶ Parse the home and away game rosters
Returns: selfon success,Noneotherwise
-
parse_scratches()[source]¶ Parse the home and away healthy scratches
Returns: selfon success,Noneotherwise
-
rosters= None¶ Rosters for both home and away. Data:
{ 'home/away': { num: { 'pos': '', 'name': '' } } }
-
scratches= None¶ Dictionary of healthy scratches keyed home/away loaded
-
nhlscrapi.scrapr.toirep module¶
-
class
nhlscrapi.scrapr.toirep.AwayTOIRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.toirep.TOIRepBaseScrapes the home team TOI report
-
class
nhlscrapi.scrapr.toirep.HomeTOIRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.toirep.TOIRepBaseScrapes the home team TOI report
-
class
nhlscrapi.scrapr.toirep.TOIRepBase(game_key, rep_type)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderScrapes TOI reports. (home/away are same format).
-
by_player= None¶ By player dictionary of shift summaries. The only events recorded per shift are
EventType.GoalorEventType.Penalty. Forperiod = 0, the game totals are returned. Format is{ player_num: { 'player_name': { 'first': '', 'last': '' }, 'shifts': [ { 'shift_num': shift_num, 'period': period_num, 'start': start_time (elapsed) 'end': end_time (elapsed) 'dur': length_of_shift, 'event': event_enum_goal_or_penalty } ], 'by_period': { 'period': period_num, 'shifts': shift_count, 'avg': { 'min': min, 'sec': sec }, 'toi': { 'min': min, 'sec': sec }, 'ev_toi': { 'min': min, 'sec': sec }, 'pp_toi': { 'min': min, 'sec': sec }, 'sh_toi': { 'min': min, 'sec': sec } } } }
-
nhlscrapi.scrapr.faceoffrep module¶
-
class
nhlscrapi.scrapr.faceoffrep.FaceOffRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load face-off comparison report from nhl.com
-
face_offs= None¶ report in dictionary format
{ home/away: { player_nums: { 'name': name, 'pos': position, 'off/def/neut/all': { 'won': won, 'total': total }, 'opps': { basically same info as above. name, pos, and zone info of opponents } } } }
-
parse()[source]¶ Retreive and parse Play by Play data for the given nhlscrapi.GameKey
Returns: selfon success,Noneotherwise
-
nhlscrapi.scrapr.eventsummrep module¶
-
class
nhlscrapi.scrapr.eventsummrep.EventSummRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load event summary report from nhl.com
-
by_team= None¶ By player team summary.
Returns: dict of the form { 'home/away': { 'num': { 'pos': pos, 'name': { 'first': first, 'last': last }, 'g/a/p/pm/pn/pim/shifts/s/ab/ms/ht/gv/tk/bs': value 'fo': { 'won': won, 'tot': total }, 'toi': { 'tot/avg/pp/sh/ev': { 'min': mins, 'sec': secs } } } } }
-
face_offs= None¶ Face off summary by strength.
Returns: dict of the form { 'home/away': { 'ev/pp/sh/tot': { 'won': goals, 'total': shots } }, } }
-
parse()[source]¶ Retreive and parse Event Summary report for the given
nhlscrapi.games.game.GameKeyReturns: selfon success,Noneotherwise
-
parse_away_by_player()[source]¶ Parse by player info for away team.
Returns: selfon success,Noneotherwise
-
parse_home_by_player()[source]¶ Parse by player info for home team.
Returns: selfon success,Noneotherwise
-
shots= None¶ The shot summary by strength at the aggregate and detail level
Returns: dict of the form { 'home/away': { 'agg': { 'ev/pp/sh/tot': { 'g': goals, 's': shots } }, 'det': { '5v5/5v4/5v3/et c': { 'g': goals, 's': shots } } } }
-
nhlscrapi.scrapr.shotsummrep module¶
-
class
nhlscrapi.scrapr.shotsummrep.ShotSummRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load shot summary report from nhl.com
nhlscrapi.scrapr.shootoutrep module¶
-
class
nhlscrapi.scrapr.shootoutrep.ShootoutRep(game_key)[source]¶ Bases:
nhlscrapi.scrapr.reportloader.ReportLoaderRetrieve and load shot summary report from nhl.com