You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
2 years ago
|
<?php
|
||
|
|
||
|
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . "/../public";
|
||
|
$projectPath = "/../public/projects/typescript/uniliga_teams/data";
|
||
|
include_once __DIR__ . $projectPath . "/php/RiotRequest.php";
|
||
|
include_once __DIR__ . $projectPath . "/php/ToorRequest.php";
|
||
|
include_once "mysql_connect.php";
|
||
|
|
||
|
$conn = new MySQLConnection();
|
||
|
$conn->changeDB("uniliga_teams");
|
||
|
|
||
|
//First, get all summonerNames of all tournaments into one list
|
||
|
$tournamentIds = json_decode(file_get_contents(__DIR__ . $projectPath . "/settings/settings.json"))->tournaments;
|
||
|
$names = [];
|
||
|
|
||
|
$i = 0;
|
||
|
do {
|
||
|
$r = new ToorRequest("participants");
|
||
|
$r->setHeaders(["Range" => "participants=$i-" . ($i + 49)]);
|
||
|
$r->setQueries(["tournament_ids" => join(",", $tournamentIds)]);
|
||
|
foreach ($r->run() as $team) {
|
||
|
foreach ($team->lineup as $player) {
|
||
|
$name = $player->custom_fields->summoner_name;
|
||
|
if (!is_null($name))
|
||
|
$names[] = $name;
|
||
|
}
|
||
|
}
|
||
|
$i += 50;
|
||
|
} while ($i < $r->getContentSize());
|
||
|
$names = array_unique($names);
|
||
|
|
||
|
$i = 0;
|
||
|
|
||
|
foreach ($names as $name) {
|
||
|
$i++;
|
||
|
$progress = round($i / count($names) * 100, 2) . "%";
|
||
|
//At max 100 calls per 120sec => 0.83 calls per second => 1.2 seconds to wait per call =>
|
||
|
//We make two riot calls => 2.4 seconds to wait
|
||
|
sleep(2);
|
||
|
usleep(500000);
|
||
|
flush();
|
||
|
|
||
|
$conn->query("DELETE FROM leagues WHERE summoner_name='$name'");
|
||
|
|
||
|
$r = new RiotRequest("lol/summoner/v4/summoners/by-name/$name");
|
||
|
$summoner = $r->run();
|
||
|
if (!$summoner) {
|
||
|
$header = $r->responseHeader;
|
||
|
$code = 0;
|
||
|
if (preg_match("#([0-9]{3})#", $header[0], $re) == 1)
|
||
|
$code = $re[1];
|
||
|
if ($code == 404)
|
||
|
echo "Summoner not found: $name\r\nProgress: $progress\r\n\r\n";
|
||
|
if ($code == 429)
|
||
|
echo "Rate limit exceeded: $name\r\n";
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$r = new RiotRequest("lol/league/v4/entries/by-summoner/$summoner->id");
|
||
|
$leagues = $r->run();
|
||
|
|
||
|
foreach ($leagues as $league) {
|
||
|
$queue = $league->queueType;
|
||
|
$tier = $league->tier;
|
||
|
$rank = $league->rank;
|
||
|
$lp = $league->leaguePoints;
|
||
|
$conn->query(
|
||
|
"INSERT INTO leagues (summoner_name, queue, tier, ranking, points)
|
||
|
VALUES ('$name', '$queue', '$tier', '$rank', '$lp')"
|
||
|
);
|
||
|
}
|
||
|
|
||
|
echo "Summoner updated: $name\r\nProgress: $progress\r\n\r\n";
|
||
|
}
|
||
|
|