commit
a3800764c0
2 changed files with 31 additions and 16 deletions
|
|
@ -23,8 +23,13 @@ $headers = @{
|
||||||
'accept' = 'application/vnd.api+json'
|
'accept' = 'application/vnd.api+json'
|
||||||
'Authorization' = "$apiKey"
|
'Authorization' = "$apiKey"
|
||||||
}
|
}
|
||||||
$claninfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/clans/$clanid" -Method GET -Headers $headers
|
try {
|
||||||
|
$claninfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/clans/$clanid" -Method GET -Headers $headers
|
||||||
|
} catch {
|
||||||
|
write-output "sleeping for 61 sec"
|
||||||
|
start-sleep -Seconds 61
|
||||||
|
$claninfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/clans/$clanid" -Method GET -Headers $headers
|
||||||
|
}
|
||||||
# Get current date and time
|
# Get current date and time
|
||||||
$currentDateTime = Get-Date
|
$currentDateTime = Get-Date
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
if($PSScriptRoot.length -eq 0){
|
if ($PSScriptRoot.length -eq 0) {
|
||||||
$scriptroot = Get-Location
|
$scriptroot = Get-Location
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
$scriptroot = $PSScriptRoot
|
$scriptroot = $PSScriptRoot
|
||||||
}
|
}
|
||||||
# Read the content of the file as a single string
|
# Read the content of the file as a single string
|
||||||
|
|
@ -33,7 +34,13 @@ $headers = @{
|
||||||
'accept' = 'application/vnd.api+json'
|
'accept' = 'application/vnd.api+json'
|
||||||
'Authorization' = "$apiKey"
|
'Authorization' = "$apiKey"
|
||||||
}
|
}
|
||||||
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers
|
try {
|
||||||
|
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers
|
||||||
|
} catch {
|
||||||
|
write-output 'Sleeping for 61 seconds'
|
||||||
|
start-sleep -Seconds 61
|
||||||
|
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers
|
||||||
|
}
|
||||||
$playerinfo.data | convertto-json -depth 100 | Out-File "$scriptroot/../data/player_data.json"
|
$playerinfo.data | convertto-json -depth 100 | Out-File "$scriptroot/../data/player_data.json"
|
||||||
$playerList = @()
|
$playerList = @()
|
||||||
$playerinfo.data | ForEach-Object {
|
$playerinfo.data | ForEach-Object {
|
||||||
|
|
@ -49,7 +56,7 @@ $playerList
|
||||||
|
|
||||||
|
|
||||||
$playeridstring = ""
|
$playeridstring = ""
|
||||||
foreach ($playerid in $playerinfo.data.id){
|
foreach ($playerid in $playerinfo.data.id) {
|
||||||
$playeridstring += "$playerid,"
|
$playeridstring += "$playerid,"
|
||||||
}
|
}
|
||||||
$playeridstring = $playeridstring.Substring(0, $playeridstring.Length - 1)
|
$playeridstring = $playeridstring.Substring(0, $playeridstring.Length - 1)
|
||||||
|
|
@ -65,17 +72,20 @@ $playermodes = @(
|
||||||
)
|
)
|
||||||
# Initialize the master hashtable
|
# Initialize the master hashtable
|
||||||
$lifetimestats = @{}
|
$lifetimestats = @{}
|
||||||
$webrequestlimiter = 0
|
|
||||||
foreach ($playmode in $playermodes) {
|
foreach ($playmode in $playermodes) {
|
||||||
# Fetch stats for the current playmode
|
# Fetch stats for the current playmode
|
||||||
if($webrequestlimiter -le 8){
|
|
||||||
write-output "Getting data for players $playeridstring gameode $playmode"
|
write-output "Getting data for players $playeridstring gameode $playmode"
|
||||||
|
|
||||||
|
try{
|
||||||
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers
|
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers
|
||||||
$webrequestlimiter++
|
} catch {
|
||||||
}else{
|
write-output 'sleeping for 61 seconds'
|
||||||
write-ouput "sleeping for 60 seconds"
|
start-sleep -Seconds 61
|
||||||
$webrequestlimiter = 0
|
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Check if the playmode doesn't exist in the hashtable, then add it
|
# Check if the playmode doesn't exist in the hashtable, then add it
|
||||||
if (-not $lifetimestats.ContainsKey($playmode)) {
|
if (-not $lifetimestats.ContainsKey($playmode)) {
|
||||||
|
|
@ -88,7 +98,7 @@ foreach ($playmode in $playermodes) {
|
||||||
$playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName
|
$playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName
|
||||||
write-output "Getting data for $playerName with gamemode $playmode"
|
write-output "Getting data for $playerName with gamemode $playmode"
|
||||||
# Fetch the specific stat data for the current stat
|
# Fetch the specific stat data for the current stat
|
||||||
$specificStat = ($stats.data | where-object {$_.relationships.player.data.id -eq $stat}).attributes.gamemodestats.$playmode
|
$specificStat = ($stats.data | where-object { $_.relationships.player.data.id -eq $stat }).attributes.gamemodestats.$playmode
|
||||||
|
|
||||||
# Create a new hashtable entry for the player and insert the specific stat data
|
# Create a new hashtable entry for the player and insert the specific stat data
|
||||||
if (-not $lifetimestats[$playmode].ContainsKey($playerName)) {
|
if (-not $lifetimestats[$playmode].ContainsKey($playerName)) {
|
||||||
|
|
@ -108,7 +118,7 @@ $currentTimezone = (Get-TimeZone).Id
|
||||||
|
|
||||||
# Format and parse the information into a string
|
# Format and parse the information into a string
|
||||||
$formattedString = "$currentDateTime - Time Zone: $currentTimezone"
|
$formattedString = "$currentDateTime - Time Zone: $currentTimezone"
|
||||||
$lifetimestats['updated']= $formattedString
|
$lifetimestats['updated'] = $formattedString
|
||||||
# Output the formatted string
|
# Output the formatted string
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue