Beispiel #1
0
def get_data(html):
	soup = BeautifulSoup(html, 'html.parser')

	data = []
	# data in all table rows inside div#allPlays>table
	for tr in soup.find(id='allPlays')('tr'):
		(period, team, eventName, eventDesc, vid) = [util.clean_str(td.text) for td in tr('td')]
		
		r = IceTrackerRow()
		if period == 'Shootout':
			r.period = 5
			r.time = None
			eventName = 'Shootout ' + eventName
		else:
			period, time = period.split(' ')
			r.period = util.get_numeric_period(period)
			r.time = time
		
		if len(team) == 0: team = None
		r.team = team

		# period end should really have an event type
		if eventDesc in ('shootout complete', 'period end'): eventName = 'Period End'
		r.event_type = eventName
		r.event_description = eventDesc
		r.details = event_handlers.handler[eventName](eventDesc)

		data.append(r)

	return data
Beispiel #2
0
def get_team_periods_from_table(table):
	periods = []
	
	# skip heading row, total row
	for tr in table('tr')[1:-1]:
		(period, goals, shots, penalties, penalty_minutes) = \
			[util.clean_nbsp(td.text).strip() for td in tr('td')]
		
		p = Period()
		# period can also be inferred by order
		p.period = util.get_numeric_period(period) 
		p.goals = int(goals)
		p.shots = int(shots)
		p.penalties = int(penalties)
		p.penalty_minutes = int(penalty_minutes)
		periods.append(p)
		
	return periods
Beispiel #3
0
def get_team_penalties_from_table(table):
	penalties = []
	
	for tr in table('tr', recursive=False)[1:]:
		(number, period, time, player, minutes, penalty_type) = \
			[util.clean_nbsp(td.text).strip() for td in tr('td', recursive=False)]
		
		p = Penalty()
		
		p.period = util.get_numeric_period(period)
		p.time = time
		
		try: p.player = util.get_integer(player)
		# Can have whole-team penalties with no player
		except ValueError: p.player = None
		
		p.minutes = int(minutes)
		p.penalty_type = penalty_type
		
		penalties.append(p)
		
	return penalties