Merge pull request #42 from OpzekerIT/dev

try catch
This commit is contained in:
Lanta 2023-09-27 22:07:18 +02:00 committed by GitHub
commit 6ceb59f679
2 changed files with 31 additions and 16 deletions

View file

@ -23,8 +23,13 @@ $headers = @{
'accept' = 'application/vnd.api+json'
'Authorization' = "$apiKey"
}
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
$currentDateTime = Get-Date

View file

@ -1,7 +1,8 @@

if ($PSScriptRoot.length -eq 0) {
$scriptroot = Get-Location
}else{
}
else {
$scriptroot = $PSScriptRoot
}
# Read the content of the file as a single string
@ -33,7 +34,13 @@ $headers = @{
'accept' = 'application/vnd.api+json'
'Authorization' = "$apiKey"
}
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"
$playerList = @()
$playerinfo.data | ForEach-Object {
@ -65,18 +72,21 @@ $playermodes = @(
)
# Initialize the master hashtable
$lifetimestats = @{}
$webrequestlimiter = 0
foreach ($playmode in $playermodes) {
# Fetch stats for the current playmode
if($webrequestlimiter -le 8){
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
} catch {
write-output 'sleeping for 61 seconds'
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
$webrequestlimiter++
}else{
write-ouput "sleeping for 60 seconds"
$webrequestlimiter = 0
}
# Check if the playmode doesn't exist in the hashtable, then add it
if (-not $lifetimestats.ContainsKey($playmode)) {
$lifetimestats[$playmode] = @{}