Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function extract-stats($raw, $playername) {
- # Get the name of the map.
- $map = [regex]::match($raw, 'Competitive.+?(?=<\/td>)').Groups[0].Value
- $map = $map.replace(' ', '').replace('Competitive ', '')
- # Get the date and time of the game.
- $datetime = [regex]::match($raw, '(....-..-.....:..:..+?(?= GMT))').Groups[0].Value
- $date = $datetime.split(' ')[0]
- $time = $datetime.split(' ')[1]
- # Get the duration of the match.
- $duration = [regex]::match($raw, '(Match Duration.+?(?=<\/td>))').Groups[0].Value
- $duration = $duration.replace('Match Duration: ', '').replace(' ', '')
- # Get the score of the match.
- $score = [regex]::match($raw, '(csgo_scoreboard_score">.+?(?=<\/td>))').Groups[0].Value
- $score = $score.replace('csgo_scoreboard_score">', '')
- $roundsWon = $score.split(' : ')[0]
- $roundsLost = $score.split(' : ')[3]
- if ($roundsWon -gt $roundsLost) {
- $result = 'win'
- } elseif ($roundsWon -lt $roundsLost) {
- $result = 'lose'
- } else {
- $result = 'draw'
- }
- # Get the player stats of the match.
- $playerStats = [regex]::match($raw, "($playername(.|[\n])+?(?=<\/tr>))").Groups[0].Value
- $playerStats = [regex]::matches($playerStats, '(<td>.+?(?=<\/td>))') | ForEach-Object { $_.Groups[0].Value }
- $playerKills = $playerStats[1].replace('<td>', '')
- $playerAssists = $playerStats[2].replace('<td>', '')
- $playerDeaths = $playerStats[3].replace('<td>', '')
- $playerHS = $playerStats[5].replace('<td>', '')
- # Build the object to extract.
- $csv = New-Object psobject
- $csv | Add-Member -MemberType NoteProperty -name 'Map' -Value $map
- $csv | Add-Member -MemberType NoteProperty -name 'Date' -Value $date
- $csv | Add-Member -MemberType NoteProperty -name 'Time' -Value $time
- $csv | Add-Member -MemberType NoteProperty -name 'Duration' -Value $duration
- $csv | Add-Member -MemberType NoteProperty -name 'Rounds Won' -Value $roundsWon
- $csv | Add-Member -MemberType NoteProperty -name 'Rounds Lost' -Value $roundsLost
- $csv | Add-Member -MemberType NoteProperty -name 'Result' -Value $result
- $csv | Add-Member -MemberType NoteProperty -name 'Kills' -Value $playerKills
- $csv | Add-Member -MemberType NoteProperty -name 'Assists' -Value $playerAssists
- $csv | Add-Member -MemberType NoteProperty -name 'Deaths' -Value $playerDeaths
- $csv | Add-Member -MemberType NoteProperty -name 'HS' -Value $playerHS
- # Export the stats to the csv file.
- Export-Csv -Path "$PSScriptRoot\stats.csv" -InputObject $csv -Append -NoTypeInformation
- }
- $path = Read-Host 'Path to the full html file'
- $playername = Read-Host 'Current Steamname'
- # Read the raw html data.
- $raw = Get-Content -Path $path -Encoding UTF8
- # Extract each match.
- $test = [regex]::matches($raw, '(Competitive(.|[\n])+?(?=csgo_scoreboard_inner_left))') | ForEach-Object {
- # Call the function to extract the stats from each match.
- extract-stats $_.Groups[0].Value $playername
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement