nhlscrapi.scrapr package

Submodules

nhlscrapi.scrapr.nhlreq module

class nhlscrapi.scrapr.nhlreq.NHLCn[source]

Bases: object

Builds 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.

away_toi(game_key)[source]
Returns:raw HTML for away TOI by player (TV)
Return type:string
event_summary(game_key)[source]
Returns:raw HTML for the event summary report (ES)
Return type:string
face_offs(game_key)[source]
Returns:raw HTML for face off comparisons (FC)
Return type:string
game_roster(game_key)[source]
Returns:raw HTML for game rosters (RO)
Return type:string
game_summary(game_key)[source]
Returns:raw HTML for game summary report (GS)
Return type:string
home_toi(game_key)[source]
Returns:raw HTML for home TOI by player (TH)
Return type:string
html_src = None

The HTML source of the last NHL page requested.

req_err = None

Error from the last HTTP request.

rtss(game_key)[source]
Returns:raw HTML for RTSS play by play (PL)
Return type:string
shootout(game_key)[source]
Returns:raw HTML for the game’s shootout (SO)
Return type:string
shot_summary(game_key)[source]
Returns:raw HTML for the shot summary report (SS)
Return type:string

nhlscrapi.scrapr.reportloader module

class nhlscrapi.scrapr.reportloader.ReportLoader(game_key, report_type='')[source]

Bases: object

Base class for objects that load full reports. Manages html request and extracts match up from banner

Parameters:
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_fromstring output
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()[source]

Fully parses html document.

Returns:self on success, None otherwise
parse_matchup()[source]

Parse the banner matchup meta info for the game.

Returns:self on success or None
report_type = None

Type of report to be loaded. Valid types correspond to the methods of NHLCn

req_err = None

Error from http request

nhlscrapi.scrapr.rtss module

class nhlscrapi.scrapr.rtss.PlayParser(season=2015)[source]

Bases: object

Interprets 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 contains nhlscrapi.games.playbyplay.Strength and nhlscrapi.games.events.EventType objects. 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
class nhlscrapi.scrapr.rtss.RTSS(game_key)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Retrieve and load RTSS play by play game data

parse()[source]

Parse full document. Plays and matchups.

Returns:self on success, None otherwise
parse_plays()[source]

Retreive and parse Play by Play data for the given nhlscrapi.games.GameKey

Returns:self on success, None otherwise
parse_plays_stream()[source]

Generate and yield a stream of parsed plays. Useful for per play processing.

plays = None

List of plays loaded. See PlayParser for play data structure.

nhlscrapi.scrapr.rosterrep module

class nhlscrapi.scrapr.rosterrep.RosterRep(game_key)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Retrieve 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:self on success, None otherwise
parse_coaches()[source]

Parse the home and away coaches

Returns:self on success, None otherwise
parse_officials()[source]

Parse the officials

Returns:self on success, None otherwise
parse_rosters()[source]

Parse the home and away game rosters

Returns:self on success, None otherwise
parse_scratches()[source]

Parse the home and away healthy scratches

Returns:self on success, None otherwise
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.TOIRepBase

Scrapes the home team TOI report

class nhlscrapi.scrapr.toirep.HomeTOIRep(game_key)[source]

Bases: nhlscrapi.scrapr.toirep.TOIRepBase

Scrapes the home team TOI report

class nhlscrapi.scrapr.toirep.TOIRepBase(game_key, rep_type)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Scrapes TOI reports. (home/away are same format).

by_player = None

By player dictionary of shift summaries. The only events recorded per shift are EventType.Goal or EventType.Penalty. For period = 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 }
        }
    }
}
parse()[source]

Parse full TOI document.

Returns:self if successful else None
parse_shifts()[source]

Parse shifts from TOI report

Returns:self if successfule else None

nhlscrapi.scrapr.faceoffrep module

class nhlscrapi.scrapr.faceoffrep.FaceOffRep(game_key)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Retrieve 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:self on success, None otherwise
parse_away_face_offs()[source]

Parse only the away faceoffs

Returns:self on success, None otherwise
parse_home_face_offs()[source]

Parse only the home faceoffs

Returns:self on success, None otherwise

nhlscrapi.scrapr.eventsummrep module

class nhlscrapi.scrapr.eventsummrep.EventSummRep(game_key)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Retrieve 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.GameKey

Returns:self on success, None otherwise
parse_away_by_player()[source]

Parse by player info for away team.

Returns:self on success, None otherwise
parse_away_fo()[source]

Parse face-off info for away team.

Returns:self on success, None otherwise
parse_away_shots()[source]

Parse shot info for away team.

Returns:self on success, None otherwise
parse_home_by_player()[source]

Parse by player info for home team.

Returns:self on success, None otherwise
parse_home_fo()[source]

Parse face-off info for home team.

Returns:self on success, None otherwise
parse_home_shots()[source]

Parse shot info for home team.

Returns:self on success, None otherwise
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.ReportLoader

Retrieve and load shot summary report from nhl.com

parse()[source]

nhlscrapi.scrapr.shootoutrep module

class nhlscrapi.scrapr.shootoutrep.ShootoutRep(game_key)[source]

Bases: nhlscrapi.scrapr.reportloader.ReportLoader

Retrieve and load shot summary report from nhl.com

parse()[source]

nhlscrapi.scrapr.gamesummrep module

nhlscrapi.scrapr.eventparser module

nhlscrapi.scrapr.eventparser.event_type_mapper(event_str, **kwargs)[source]
nhlscrapi.scrapr.eventparser.parse_event_desc(event, season=2008)[source]

nhlscrapi.scrapr.descparser module

nhlscrapi.scrapr.descparser.assist_from(a)[source]
nhlscrapi.scrapr.descparser.default_desc_parser(event)[source]
nhlscrapi.scrapr.descparser.get_ft(s, def_dist=-1)[source]
nhlscrapi.scrapr.descparser.parse_block_08(event)[source]
nhlscrapi.scrapr.descparser.parse_faceoff_08(event)[source]
nhlscrapi.scrapr.descparser.parse_giveaway_08(event)[source]
nhlscrapi.scrapr.descparser.parse_goal_desc_08(event)[source]
nhlscrapi.scrapr.descparser.parse_hit_08(event)[source]
nhlscrapi.scrapr.descparser.parse_miss_08(event)[source]
nhlscrapi.scrapr.descparser.parse_shootout(event)[source]
nhlscrapi.scrapr.descparser.parse_shot_desc_08(event)[source]
nhlscrapi.scrapr.descparser.parse_takeaway_08(event)[source]
nhlscrapi.scrapr.descparser.rem_char(s, c)[source]
nhlscrapi.scrapr.descparser.rem_penalty_shot_desc(s)[source]
nhlscrapi.scrapr.descparser.split_and_strip(s, by)[source]
nhlscrapi.scrapr.descparser.team_num_name(s)[source]

nhlscrapi.scrapr.officialsparser module

nhlscrapi.scrapr.officialsparser.official_parser_10(lx_doc)[source]
nhlscrapi.scrapr.officialsparser.official_parser_mapper(season)[source]
nhlscrapi.scrapr.officialsparser.official_parser_pre_09(lx_doc)[source]

nhlscrapi.scrapr.teamnameparser module

nhlscrapi.scrapr.teamnameparser.team_abbr_parser(abr)[source]
nhlscrapi.scrapr.teamnameparser.team_name_parser(name)[source]

Module contents