Exemplo n.º 1
0
def prune_tombstone(tree):
	'''
	Using passed xml tree, grab data from player tombstone
	'''

	temp_player = PP_Player () # Container for player information
	
	info_raw = tree.xpath('//div[@id="tombstone"]/div/table//tr/td/text()')
	website_raw = tree.xpath('//div[@id="tombstone"]//div[@id="playerSite"]/a/@href')
	position_raw = tree.xpath('//div[@id="tombstone"]/div/div/span/text()')
	twitter_raw = tree.xpath('//div[@id="tombstone"]/div/table/tr/td/a/@href')
	team_position_raw = tree.xpath('//div[@id="tombstone"]/div/div[@style="float: left; margin-left: 6px; font-weight: bold; color: #999;"]')
	team_raw = team_position_raw[0].xpath ('./a/text()')
	position_raw = team_position_raw[0].xpath ('./span/text()')
	
	info_stripped = [x.strip() for x in info_raw]
	info_iter = iter(info_stripped)
	for item in info_iter:
		if item == "NUMBER:":
			temp_player.current_num = next(info_iter)
		elif item == "HEIGHT:":
			try:
				height_raw = next(info_iter).split ("\' ")
				temp_player.height = height_raw[0] + ',' + height_raw[1].strip('"')
			except IndexError:
				temp_player.height = None
		elif item == "WEIGHT:":
			temp_player.weight = next(info_iter)
		elif item == "DRAFTED:":
			temp_player.draft_team = next(info_iter).strip('/').strip().strip()
		elif item == "Shoots:":
			temp_player.shoots = next(info_iter)
		elif item == "Catches:":
			temp_player.shoots = next(info_iter)
		elif item == "ROUND:":
			temp_player.draft_round = next(info_iter)
			temp_player.draft_overall = next(info_iter).strip('()')

	try:
		temp_player.website = website_raw [0]
	except IndexError:
		pass
	try:
		temp_player.position_page = position_raw [0][0]
	except IndexError:
		pass
	try:
		temp_player.current_team = Operations.team_name_to_acronym(team_raw[0])
	except IndexError:
		pass
	try:
		temp_player.position_page = position_raw [0]
	except IndexError:
		pass

	for item in twitter_raw:
		if item.find ("/ice/draftsearch.htm?team=") != -1:
			temp_player.draft_year = item.split ('=') [-1]
		elif item.find ("https://twitter.com/") != -1:
			temp_player.twitter = item.split('/') [-1]
	
	return temp_player