Advertisement
Guest User

csgo data extraction

a guest
May 25th, 2018
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. function extract-stats($raw, $playername) {
  2. # Get the name of the map.
  3. $map = [regex]::match($raw, 'Competitive.+?(?=<\/td>)').Groups[0].Value
  4. $map = $map.replace(' ', '').replace('Competitive ', '')
  5.  
  6. # Get the date and time of the game.
  7. $datetime = [regex]::match($raw, '(....-..-.....:..:..+?(?= GMT))').Groups[0].Value
  8. $date = $datetime.split(' ')[0]
  9. $time = $datetime.split(' ')[1]
  10.  
  11. # Get the duration of the match.
  12. $duration = [regex]::match($raw, '(Match Duration.+?(?=<\/td>))').Groups[0].Value
  13. $duration = $duration.replace('Match Duration: ', '').replace(' ', '')
  14.  
  15. # Get the score of the match.
  16. $score = [regex]::match($raw, '(csgo_scoreboard_score">.+?(?=<\/td>))').Groups[0].Value
  17. $score = $score.replace('csgo_scoreboard_score">', '')
  18. $roundsWon = $score.split(' : ')[0]
  19. $roundsLost = $score.split(' : ')[3]
  20. if ($roundsWon -gt $roundsLost) {
  21. $result = 'win'
  22. } elseif ($roundsWon -lt $roundsLost) {
  23. $result = 'lose'
  24. } else {
  25. $result = 'draw'
  26. }
  27.  
  28. # Get the player stats of the match.
  29. $playerStats = [regex]::match($raw, "($playername(.|[\n])+?(?=<\/tr>))").Groups[0].Value
  30. $playerStats = [regex]::matches($playerStats, '(<td>.+?(?=<\/td>))') | ForEach-Object { $_.Groups[0].Value }
  31. $playerKills = $playerStats[1].replace('<td>', '')
  32. $playerAssists = $playerStats[2].replace('<td>', '')
  33. $playerDeaths = $playerStats[3].replace('<td>', '')
  34. $playerHS = $playerStats[5].replace('<td>', '')
  35.  
  36. # Build the object to extract.
  37. $csv = New-Object psobject
  38. $csv | Add-Member -MemberType NoteProperty -name 'Map' -Value $map
  39. $csv | Add-Member -MemberType NoteProperty -name 'Date' -Value $date
  40. $csv | Add-Member -MemberType NoteProperty -name 'Time' -Value $time
  41. $csv | Add-Member -MemberType NoteProperty -name 'Duration' -Value $duration
  42. $csv | Add-Member -MemberType NoteProperty -name 'Rounds Won' -Value $roundsWon
  43. $csv | Add-Member -MemberType NoteProperty -name 'Rounds Lost' -Value $roundsLost
  44. $csv | Add-Member -MemberType NoteProperty -name 'Result' -Value $result
  45. $csv | Add-Member -MemberType NoteProperty -name 'Kills' -Value $playerKills
  46. $csv | Add-Member -MemberType NoteProperty -name 'Assists' -Value $playerAssists
  47. $csv | Add-Member -MemberType NoteProperty -name 'Deaths' -Value $playerDeaths
  48. $csv | Add-Member -MemberType NoteProperty -name 'HS' -Value $playerHS
  49.  
  50. # Export the stats to the csv file.
  51. Export-Csv -Path "$PSScriptRoot\stats.csv" -InputObject $csv -Append -NoTypeInformation
  52. }
  53.  
  54. $path = Read-Host 'Path to the full html file'
  55. $playername = Read-Host 'Current Steamname'
  56.  
  57. # Read the raw html data.
  58. $raw = Get-Content -Path $path -Encoding UTF8
  59.  
  60. # Extract each match.
  61. $test = [regex]::matches($raw, '(Competitive(.|[\n])+?(?=csgo_scoreboard_inner_left))') | ForEach-Object {
  62. # Call the function to extract the stats from each match.
  63. extract-stats $_.Groups[0].Value $playername
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement