You're speaking a language that I don't understand buddy. I was able to follow the instructions higher up in this thread, but my understanding stops there.doogiski wrote: ↑Mon Nov 20, 2023 3:26 pmIt looks like you can obtain this information by using the URL from the network console when viewing thestats page on NHL.com <https://www.nhl.com/stats/skaters?repor ... ageSize=50>.
IE. the API url that returns all the information to show the points stat leaders is https://api.nhle.com/stats/rest/en/skat ... E=20232024
The API has a record limit of 100 records per page so pagination will need to be implemented. Judging by the total field at the bottom of each JSON object returned, 734 players have played at least 1 NHL game this season. If you need help extracting and parsing this information, let me know.
NHL API Powershell Scripts.
-
- The Crazy / Le Fou
- Posts: 403
- Joined: Tue Feb 28, 2006 10:37 am
- Location: Oslo, Norway
- Contact:
Re: NHL API Powershell Scripts.
Re: NHL API Powershell Scripts.
I wrote the script in Python, but since I don't know how to script in Powershell I used ChatGPT to convert it into a Powershell script. This works when I run it only my machine. It creates a CSV of the 748 to-date that have played in at least one NHL game this season. It only returns the player id and full name right now.laving wrote: ↑Fri Nov 24, 2023 2:20 pmYou're speaking a language that I don't understand buddy. I was able to follow the instructions higher up in this thread, but my understanding stops there.doogiski wrote: ↑Mon Nov 20, 2023 3:26 pmIt looks like you can obtain this information by using the URL from the network console when viewing thestats page on NHL.com <https://www.nhl.com/stats/skaters?repor ... ageSize=50>.
IE. the API url that returns all the information to show the points stat leaders is https://api.nhle.com/stats/rest/en/skat ... E=20232024
The API has a record limit of 100 records per page so pagination will need to be implemented. Judging by the total field at the bottom of each JSON object returned, 734 players have played at least 1 NHL game this season. If you need help extracting and parsing this information, let me know.
Code: Select all
# API call to determine how many pages
$response = Invoke-RestMethod -Uri "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=100&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024" -Method Get
$count = $response.total
$pages = [math]::ceiling($count / 100)
# Loop through pages
$players = @()
for ($i = 0; $i -lt $pages; $i++) {
$urlPaged = "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=$($i * 100)&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024"
$responsePaged = Invoke-RestMethod -Uri $urlPaged -Method Get
$data = $responsePaged.data
foreach ($d in $data) {
$players += [PsCustomObject]@{
playerId = $d.playerId
skaterFullName = $d.skaterFullName
}
}
}
# Export data to CSV
$players | Export-Csv -Path 'skater_info.csv' -NoTypeInformation
-
- The Crazy / Le Fou
- Posts: 403
- Joined: Tue Feb 28, 2006 10:37 am
- Location: Oslo, Norway
- Contact:
Re: NHL API Powershell Scripts.
Oooh. I'd be happy to try that out.doogiski wrote: ↑Wed Nov 29, 2023 2:06 pmI wrote the script in Python, but since I don't know how to script in Powershell I used ChatGPT to convert it into a Powershell script. This works when I run it only my machine. It creates a CSV of the 748 to-date that have played in at least one NHL game this season. It only returns the player id and full name right now.laving wrote: ↑Fri Nov 24, 2023 2:20 pmYou're speaking a language that I don't understand buddy. I was able to follow the instructions higher up in this thread, but my understanding stops there.doogiski wrote: ↑Mon Nov 20, 2023 3:26 pm
It looks like you can obtain this information by using the URL from the network console when viewing thestats page on NHL.com <https://www.nhl.com/stats/skaters?repor ... ageSize=50>.
IE. the API url that returns all the information to show the points stat leaders is https://api.nhle.com/stats/rest/en/skat ... E=20232024
The API has a record limit of 100 records per page so pagination will need to be implemented. Judging by the total field at the bottom of each JSON object returned, 734 players have played at least 1 NHL game this season. If you need help extracting and parsing this information, let me know.
Code: Select all
# API call to determine how many pages $response = Invoke-RestMethod -Uri "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=100&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024" -Method Get $count = $response.total $pages = [math]::ceiling($count / 100) # Loop through pages $players = @() for ($i = 0; $i -lt $pages; $i++) { $urlPaged = "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=$($i * 100)&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024" $responsePaged = Invoke-RestMethod -Uri $urlPaged -Method Get $data = $responsePaged.data foreach ($d in $data) { $players += [PsCustomObject]@{ playerId = $d.playerId skaterFullName = $d.skaterFullName } } } # Export data to CSV $players | Export-Csv -Path 'skater_info.csv' -NoTypeInformation
Re: NHL API Powershell Scripts.
doogiski wrote: ↑Wed Nov 29, 2023 2:06 pmI wrote the script in Python, but since I don't know how to script in Powershell I used ChatGPT to convert it into a Powershell script. This works when I run it only my machine. It creates a CSV of the 748 to-date that have played in at least one NHL game this season. It only returns the player id and full name right now.laving wrote: ↑Fri Nov 24, 2023 2:20 pmYou're speaking a language that I don't understand buddy. I was able to follow the instructions higher up in this thread, but my understanding stops there.doogiski wrote: ↑Mon Nov 20, 2023 3:26 pm
It looks like you can obtain this information by using the URL from the network console when viewing thestats page on NHL.com <https://www.nhl.com/stats/skaters?repor ... ageSize=50>.
IE. the API url that returns all the information to show the points stat leaders is https://api.nhle.com/stats/rest/en/skat ... E=20232024
The API has a record limit of 100 records per page so pagination will need to be implemented. Judging by the total field at the bottom of each JSON object returned, 734 players have played at least 1 NHL game this season. If you need help extracting and parsing this information, let me know.
Code: Select all
# API call to determine how many pages $response = Invoke-RestMethod -Uri "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=100&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024" -Method Get $count = $response.total $pages = [math]::ceiling($count / 100) # Loop through pages $players = @() for ($i = 0; $i -lt $pages; $i++) { $urlPaged = "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=false&sort=[{%22property%22:%22points%22,%22direction%22:%22DESC%22},{%22property%22:%22playerId%22,%22direction%22:%22ASC%22}]&start=0&limit=$($i * 100)&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameTypeId=2%20and%20seasonId%3C=20232024%20and%20seasonId%3E=20232024" $responsePaged = Invoke-RestMethod -Uri $urlPaged -Method Get $data = $responsePaged.data foreach ($d in $data) { $players += [PsCustomObject]@{ playerId = $d.playerId skaterFullName = $d.skaterFullName } } } # Export data to CSV $players | Export-Csv -Path 'skater_info.csv' -NoTypeInformation
Do you think you could adapt it so it create a file with every id? not just NHL games played?
I figured the file would be insanely huge, but updating it in STHS would discard players not created, and update every single players, even those in the farm, right?