While searching on the Internet, I came across this very interesting post (http://hfboards.hockeysfuture.com/showt ... ?t=1596119 ) regarding NHL JSON Data. So I build a Powershell V3 script to extract this data to CSV. The CSV has a lot of interesting information. Personally, I was looking for the players name and team abbreviation information to use with the “Assign Players to Team CSV” function. Here is my script.
This code doesn't work anymore. Please look below.
Code: Select all
function Get-NHLData{
Write-Host "Fethcing" $URL
$Data = Invoke-RestMethod -uri $URL
$Data.goalie | Add-Member -MemberType NoteProperty -Name Team -Value $Team
$Data.defensemen | Add-Member -MemberType NoteProperty -Name Team -Value $Team
$Data.forwards | Add-Member -MemberType NoteProperty -Name Team -Value $Team
$Data.goalie | Export-csv $File -Append -NoTypeInformation -Force
$Data.defensemen | Export-csv $File -Append -NoTypeInformation -Force
$Data.forwards | Export-csv $File -Append -NoTypeInformation -Force
}
$File = "NHLData.csv"
If(Test-Path -Path $file){Remove-Item $File}
$NHLTeamArray = @("ANA","ARI","BOS","BUF","CAR","CBJ","CGY","CHI","COL","DAL","DET","EDM","FLA","LAK","MIN","MTL","NJD","NSH","NYI","NYR","OTT","PHI","PIT","SJS","STL","TBL","TOR","VAN","WPG","WSH")
ForEach($Team in $NHLTeamArray){
$URL = "http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/"+$Team+"/iphone/clubroster.json"
Get-NHLData -url $URL
}
If Powershell is completely unknown to you, it’s build-in in Windows. Simply search for “Windows PowerShell ISE” on your computer, open it, copy the script in the top pane, change the $FilePath variable path at line 12 and run the script. You’ll get a very nice CSV files with a bunch of information directly from NHL.com!
Good luck and enjoy!
Edit Novembre 2017. The old code doesn't seem to work. Try this one.
Code: Select all
$File = "NHLData.csv"
If(Test-Path -Path $file){Remove-Item $File}
$JSON = Invoke-RestMethod -uri "https://statsapi.web.nhl.com/api/v1/teams?expand=team.roster&season=20172018&site=en_nhl"
$Team = $JSON.teams
ForEach($TeamData in $Team){
$TeamAbre = $TeamData.abbreviation
Write-host $TeamAbre -BackgroundColor Green
ForEach($Person in $TeamData.roster.roster.person){
$Person | Add-Member -MemberType NoteProperty -Name Team -Value $TeamAbre
$Person | Export-csv $File -Append -NoTypeInformation -Force
}
}