archiving and building matches caches file
This commit is contained in:
parent
f545187cfb
commit
9c6d1501bc
1 changed files with 37 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ new-lock -by "get_matches"
|
||||||
|
|
||||||
# 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
|
||||||
|
$players = (Get-Content -Path "$scriptroot/../config/clanmembers.json" | ConvertFrom-Json).clanmembers
|
||||||
# Use regex to match the apiKey value
|
# Use regex to match the apiKey value
|
||||||
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
||||||
$apiKey = $matches[1]
|
$apiKey = $matches[1]
|
||||||
|
|
@ -37,7 +37,8 @@ foreach ($player in $player_data) {
|
||||||
if (Test-Path "$scriptroot/../data/matches/$match.json") {
|
if (Test-Path "$scriptroot/../data/matches/$match.json") {
|
||||||
write-output "Getting $match from cache"
|
write-output "Getting $match from cache"
|
||||||
$stats = get-content "$scriptroot/../data/matches/$match.json" | convertfrom-json
|
$stats = get-content "$scriptroot/../data/matches/$match.json" | convertfrom-json
|
||||||
}else{
|
}
|
||||||
|
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"
|
$stats | ConvertTo-Json -Depth 100 | Out-File "$scriptroot/../data/matches/$match.json"
|
||||||
}
|
}
|
||||||
|
|
@ -76,8 +77,6 @@ if (test-path "$scriptroot/../data/player_matches.json") {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$currentDateTime = Get-Date
|
$currentDateTime = Get-Date
|
||||||
|
|
||||||
# Get current timezone
|
# Get current timezone
|
||||||
|
|
@ -92,5 +91,36 @@ $playermatches += [PSCustomObject]@{
|
||||||
|
|
||||||
$player_matches | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_matches.json"
|
$player_matches | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_matches.json"
|
||||||
|
|
||||||
|
write-output 'Cleaning matches'
|
||||||
|
|
||||||
|
$matchfiles = Get-ChildItem "$scriptroot/../data/matches" -Filter *.json
|
||||||
|
$player_matches_object = @()
|
||||||
|
foreach ($file in $matchfiles) {
|
||||||
|
$filecontent = get-content $file | convertfrom-json
|
||||||
|
$matchfiledate = $filecontent.data.attributes.createdAt
|
||||||
|
if ($matchfiledate -lt (get-date).AddMonths(-1)) {
|
||||||
|
write-output "archiving $matchfiledate"
|
||||||
|
Move-Item -Path $file -Destination "$scriptroot/../data/matches/archive"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$result = ($filecontent.included | where-object { $_.type -eq 'participant' } | Where-Object { $players -contains $_.attributes.stats.name })
|
||||||
|
$filecontent.data.id
|
||||||
|
$result.count
|
||||||
|
$player_matches_cached = ($filecontent.included | where-object { $_.type -eq 'participant' } | Where-Object { $players -contains $_.attributes.stats.name }).attributes.stats
|
||||||
|
if ($null -ne $player_matches_cached) {
|
||||||
|
$player_matches_object += [PSCustomObject]@{
|
||||||
|
matchType = $filecontent.data.attributes.matchType
|
||||||
|
gameMode = $filecontent.data.attributes.gameMode
|
||||||
|
createdAt = $filecontent.data.attributes.createdAt
|
||||||
|
mapName = $filecontent.data.attributes.mapName
|
||||||
|
id = $filecontent.data.id
|
||||||
|
stats = $player_matches_cached
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write-output "NEW $matchfiledate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$player_matches_object | convertto-json -Depth 100 | out-file "$scriptroot/../data/cached_matches.json"
|
||||||
|
|
||||||
remove-lock
|
remove-lock
|
||||||
Stop-Transcript
|
Stop-Transcript
|
||||||
Loading…
Add table
Add a link
Reference in a new issue