get matches from cache and lock fix

This commit is contained in:
Thijs Stobbelaar 2023-11-13 19:38:34 +01:00
parent b44c11109a
commit e1b379780e
2 changed files with 26 additions and 12 deletions

13
config/clanmembers.json Normal file
View file

@ -0,0 +1,13 @@
{
"clanMembers": [
"Lanta01",
"Petje1972",
"TaGMoM",
"r00tger",
"Masistuta",
"RalphNorris",
"Jimbo_The_One",
"SquadKiller101",
"Pettie1972"
]
}

View file

@ -1,7 +1,3 @@
. .\..\includes\ps1\lockfile.ps1
new-lock
if ($PSScriptRoot.length -eq 0) { if ($PSScriptRoot.length -eq 0) {
$scriptroot = Get-Location $scriptroot = Get-Location
} }
@ -9,7 +5,8 @@ else {
$scriptroot = $PSScriptRoot $scriptroot = $PSScriptRoot
} }
. $scriptroot\..\includes\ps1\lockfile.ps1
new-lock
# Read the content of the file as a single string # Read the content of the file as a single string
$fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw $fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw
@ -22,12 +19,9 @@ else {
Write-Output "API Key not found" Write-Output "API Key not found"
} }
if ($fileContent -match "\`$clanmembers\s*=\s*array\(([^)]+)\)") { $clanMembersArray = (Get-Content "$scriptroot/../config/clanmembers.json" | convertfrom-json).clanmembers
# Remove quotes and split by comma to get individual members
$clanMembers = ($matches[1] -replace '"|\'', '' -split ","').replace(" ", "")
$clanMembersArray = $clanMembers.split(",").trim()
Write-Output "Clan Members: $($clanMembersArray -join ', ')" Write-Output "Clan Members: $($clanMembersArray -join ', ')"
}
else { else {
Write-Output "Clan members not found" Write-Output "Clan members not found"
} }
@ -49,7 +43,14 @@ foreach ($player in $player_data) {
$playermatches = @() $playermatches = @()
foreach ($match in $lastMatches) { foreach ($match in $lastMatches) {
Write-Host "Getting match for $($player.attributes.name) match: $match " Write-Host "Getting match for $($player.attributes.name) match: $match "
if(Test-Path "$scriptroot/../data/matches/$match.json"){
write-output "Getting $match from cache"
$stats = get-content "$scriptroot/../data/matches/$match.json" | convertfrom-json
}else{
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/matches/$match" -Method GET -Headers $headers $stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/matches/$match" -Method GET -Headers $headers
$stats | ConvertTo-Json -Depth 100 | Out-File "$scriptroot/../data/matches/$match.json"
}
$playermatches += [PSCustomObject]@{ $playermatches += [PSCustomObject]@{
stats = $stats.included.ATTRIBUTES.stats | where-object { $_.name -eq $player.attributes.name } stats = $stats.included.ATTRIBUTES.stats | where-object { $_.name -eq $player.attributes.name }
matchType = $stats.data.attributes.matchtype matchType = $stats.data.attributes.matchtype