multiple users possible + wacky

This commit is contained in:
Thijs Stobbelaar 2023-11-14 15:55:15 +01:00
parent 413e69a955
commit e4aace6b83
3 changed files with 89 additions and 42 deletions

View file

@ -8,6 +8,8 @@
"RalphNorris", "RalphNorris",
"Jimbo_The_One", "Jimbo_The_One",
"SquadKiller101", "SquadKiller101",
"Pettie1972" "Pettie1972",
"HeteKip",
"WackyJacky101"
] ]
} }

View file

@ -63,7 +63,7 @@ $map_map = @{
} }
$player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 $player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100
$new_win_matches = $player_matches.new_win_matches $new_win_matches = $player_matches[-1].new_win_matches
foreach ($winid in $new_win_matches) { foreach ($winid in $new_win_matches) {

View file

@ -24,24 +24,48 @@ else {
} }
$clanMembersArray = (get-content "$scriptroot/../config/clanmembers.json" | convertfrom-json).clanMembers $clanMembersArray = (Get-Content "$scriptroot/../config/clanmembers.json" | ConvertFrom-Json).clanMembers
$clanmemberchunks = @()
$chunk = @()
$chunksize = 10
$i = 0
foreach ($member in $clanMembersArray) {
$chunk += $member
if ($chunk.Count -eq $chunksize) {
$clanmemberchunks += @{ "Chunk$i" = $chunk }
$chunk = @()
$i++
}
}
# Add any remaining members to the last chunk
if ($chunk.Count -gt 0) {
$clanmemberchunks += @{ "Chunk$i" = $chunk }
}
$clanMembers = $clanMembersArray -join ',' $clanMembers = $clanMembersArray -join ','
if ($clanMembersArray.count -gt 10 ) {
write-output "Currently not able to process more then 10 players"
exit
}
$headers = @{ $headers = @{
'accept' = 'application/vnd.api+json' 'accept' = 'application/vnd.api+json'
'Authorization' = "$apiKey" 'Authorization' = "$apiKey"
} }
try { $playerinfo = @()
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers foreach ($key in $clanmemberchunks.keys) {
} catch {
$clanMembers = $clanmemberchunks.$key -join ','
$clanMembers
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' write-output 'Sleeping for 61 seconds'
start-sleep -Seconds 61 start-sleep -Seconds 61
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers $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 = @()
@ -57,12 +81,32 @@ $playerinfo.data | ForEach-Object {
$playerList $playerList
$playeridstring = ""
foreach ($playerid in $playerinfo.data.id) {
$playeridstring += "$playerid,"
}
$playeridstring = $playeridstring.Substring(0, $playeridstring.Length - 1)
$playerChunks = @{}
$chunk = @()
$chunksize = 10
$i = 0
foreach ($player in $playerList) {
$chunkName = "Chunk$i"
$chunk += $player
if ($chunk.Count -eq $chunksize) {
$playerChunks[$chunkName] = $chunk
$chunk = @()
$i++
}
}
# Add any remaining players to the last chunk
if ($chunk.Count -gt 0) {
$playerChunks["Chunk$i"] = $chunk
}
$playeridstringarray = @()
foreach ($key in $playerChunks.keys) {
$playeridstringarray += $playerChunks.$key.PlayerID -join ','
}
$playermodes = @( $playermodes = @(
"solo", "solo",
@ -74,15 +118,16 @@ $playermodes = @(
) )
# Initialize the master hashtable # Initialize the master hashtable
$lifetimestats = @{} $lifetimestats = @{}
foreach ($playeridstring in $playeridstringarray) {
foreach ($playmode in $playermodes) { foreach ($playmode in $playermodes) {
# Fetch stats for the current playmode # Fetch stats for the current playmode
write-output "Getting data for players $playeridstring gameode $playmode" write-output "Getting data for players $playeridstring gameode $playmode"
try{ 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
} catch { }
catch {
write-output 'sleeping for 61 seconds' write-output 'sleeping for 61 seconds'
start-sleep -Seconds 61 start-sleep -Seconds 61
$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
@ -108,10 +153,10 @@ foreach ($playmode in $playermodes) {
} }
$lifetimestats[$playmode][$playerName][$stat] = $specificStat $lifetimestats[$playmode][$playerName][$stat] = $specificStat
} }
}
} }
# Get current date and time # Get current date and time
$currentDateTime = Get-Date $currentDateTime = Get-Date