Beispiel #1
0
	def loadGamePlayers(self,game):
		printerObj.debugPrint("get request to " + game.url)
		try:
			page = requests.get(game.url)
		except requests.exceptions.RequestException as e:
			print("Error in load game players")
			return
		tree = html.fromstring(page.content);

		playerStats =  tree.xpath('//*[@id="my-players-table"]/*/div[2]/table/thead/tr/td/*/div/table/tbody[1]/*');
		for player in playerStats:
			try:
				if not player.xpath('td[1]/a/text()') or not player.xpath('td[9]/text()'):
					continue;
				url = player.xpath('td[1]/a/@href')[0]
				name = player.xpath('td[1]/a/text()')[0]
				goals = int(player.xpath('td[2]/text()')[0])
				assists = int(player.xpath('td[3]/text()')[0])
				plusminus = int(player.xpath('td[4]/text()')[0])
				sog = int(player.xpath('td[5]/text()')[0])
				pim = int(player.xpath('td[9]/text()')[0])
				playerObj = Player()
				playerObj.setSkater(name,goals,assists,plusminus,pim,sog,url)
				self.playerList.append(playerObj)
			except:
				continue
		playerStats =  tree.xpath('//*[@id="my-players-table"]/*/div[2]/table/thead/tr/*/div/div/table/tbody/*')
		first=True
		for player in playerStats:
			try:
				if not player.xpath('td[1]/a/text()') or not player.xpath('td[6]/text()'):
					tempPlayer = player.xpath('td[1]/a/text()')
					continue;
				name = player.xpath('td[1]/a/text()')[0]
				url = player.xpath('td[1]/a/@href')[0]
				goalsAllowed=int(player.xpath('td[3]/text()')[0])
				saveper=float(player.xpath('td[5]/text()')[0])
				toi=player.xpath('td[6]/text()')[0]
				minutes=int(toi.split(':')[0])
				if minutes<30:
					continue
				seconds=float(toi.split(':')[1])
				seconds=seconds/60.0
				amountofgame=(minutes+seconds)/60
				gaa=goalsAllowed/amountofgame
				if first:
					if game.awayScore>game.homeScore and game.gameEnded==True:
						wins=1
					else:
						wins=0
					first = False
				else:
					if game.homeScore>game.awayScore and game.gameEnded==True:
						wins=1
					else:
						wins=0
				if goalsAllowed==0:
					so=1
				else:
					so=0
				playerObj = Player()
				playerObj.setGoalie(name,wins,saveper,gaa,so,url)
				playerObj.score=playerObj.score*amountofgame
				self.playerList.append(playerObj)
			except:
				continue
		return