Update data with cron to prevent api rate limiting
This commit is contained in:
parent
d1ea67e18c
commit
5b15fddfe9
8 changed files with 1006 additions and 122 deletions
25
update/update_clan.ps1
Normal file
25
update/update_clan.ps1
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
# Read the content of the file as a single string
|
||||
$fileContent = Get-Content -Path "../config/config.php" -Raw
|
||||
|
||||
# Use regex to match the apiKey value
|
||||
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
||||
$apiKey = $matches[1]
|
||||
}else {
|
||||
Write-Output "API Key not found"
|
||||
}
|
||||
|
||||
if ($fileContent -match "\`$clanid\s*=\s*\'([^\']+)\'") {
|
||||
$clanid = $matches[1]
|
||||
} else {
|
||||
Write-Output "No clanid found in $configPath"
|
||||
}
|
||||
|
||||
|
||||
|
||||
$headers = @{
|
||||
'accept' = 'application/vnd.api+json'
|
||||
'Authorization' = "$apiKey"
|
||||
}
|
||||
$claninfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/clans/$clanid" -Method GET -Headers $headers
|
||||
$claninfo.data.attributes | convertto-json -Depth 100 | out-file '../data/claninfo.json'
|
||||
94
update/update_clan_members.ps1
Normal file
94
update/update_clan_members.ps1
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
|
||||
# Read the content of the file as a single string
|
||||
$fileContent = Get-Content -Path "../config/config.php" -Raw
|
||||
|
||||
# Use regex to match the apiKey value
|
||||
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
||||
$apiKey = $matches[1]
|
||||
}
|
||||
else {
|
||||
Write-Output "API Key not found"
|
||||
}
|
||||
|
||||
if ($fileContent -match "\`$clanmembers\s*=\s*array\(([^)]+)\)") {
|
||||
# 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 ', ')"
|
||||
}
|
||||
else {
|
||||
Write-Output "Clan members not found"
|
||||
}
|
||||
if ($clanMembersArray.count -ge 10 ) {
|
||||
write-output "Currently not able to process more then 10 players"
|
||||
exit
|
||||
}
|
||||
|
||||
$headers = @{
|
||||
'accept' = 'application/vnd.api+json'
|
||||
'Authorization' = "$apiKey"
|
||||
}
|
||||
$playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers
|
||||
|
||||
$playerList = @()
|
||||
$playerinfo.data | ForEach-Object {
|
||||
$playerObject = [PSCustomObject]@{
|
||||
PlayerName = $_.attributes.name
|
||||
PlayerID = $_.id
|
||||
}
|
||||
$playerList += $playerObject
|
||||
}
|
||||
|
||||
# Display the list
|
||||
$playerList
|
||||
|
||||
|
||||
$playeridstring = ""
|
||||
foreach ($playerid in $playerinfo.data.id){
|
||||
$playeridstring += "$playerid,"
|
||||
}
|
||||
$playeridstring = $playeridstring.Substring(0, $playeridstring.Length - 1)
|
||||
|
||||
|
||||
$playermodes = @(
|
||||
"solo",
|
||||
"duo",
|
||||
"squad"
|
||||
#"solo-fpp",
|
||||
#"duo-fpp",
|
||||
#"squad-fpp"
|
||||
)
|
||||
# Initialize the master hashtable
|
||||
$lifetimestats = @{}
|
||||
$webrequestlimiter = 0
|
||||
foreach ($playmode in $playermodes) {
|
||||
# Fetch stats for the current playmode
|
||||
if($webrequestlimiter -le 8){
|
||||
$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] = @{}
|
||||
}
|
||||
|
||||
foreach ($stat in $stats.data.relationships.player.data.id) {
|
||||
|
||||
# Fetch the player name for the current stat (account ID) from the dictionary
|
||||
$playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName
|
||||
|
||||
# Fetch the specific stat data for the current stat
|
||||
$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
|
||||
if (-not $lifetimestats[$playmode].ContainsKey($playerName)) {
|
||||
$lifetimestats[$playmode][$playerName] = @{}
|
||||
}
|
||||
$lifetimestats[$playmode][$playerName][$stat] = $specificStat
|
||||
}
|
||||
}
|
||||
$lifetimestats | convertto-json -Depth 100 | out-file '../data/player_lifetime_data.json'
|
||||
Loading…
Add table
Add a link
Reference in a new issue