示例#1
0
def set_game_info(self, soup):
	"""
	Sets the times, duration, venue, and attendance for a game
	"""
	(date, venue, time, gameNumber, final) = [tr.text.strip() for tr in soup.find(id='GameInfo')('tr')[3:8]]
	
	# time originally like "Start 7:15 EDT; End 9:55 EDT"
	# note 12-hour time, assume always PM
	try:
		(start, end) = time.split('; ')
	except ValueError:
		# time will only be "Start : TimeZoneAbbr" if game went unplayed
		raise ValueError('Report is empty')
		
	start_time = start[6:-4]
	end_time = end[4:-4]
	
	# timezone is consistent across host venue and not captured here
	# should process timezone and daylight savings changes in analytics, however 
	time_zone = end[-3:]
	
	self.set_timespan(
		get_nhl_datetime(date, start_time),
		get_nhl_datetime(date, end_time)
	)
	
	# venue originally like "Attendance 19,745 at Air Canada Centre"
	venue = util.clean_nbsp(venue).split(' ')
	
	# attendance not always available
	if len(venue[1]) > 0:
		self.attendance = int(venue[1].replace(',',''))
	
	self.venue = ' '.join(venue[3:])
示例#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
示例#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