<?php /** * Retrieves match information of one json file and stores the data in MongoDB. * Automatically detects region from filename. */ require "classes/riot-league-api.php"; require "classes/rate-limit.php"; require "classes/settings.php"; $api = new RiotLeagueAPI("na", $league_api_key); $time = new RateLimit(); $mongo = new MongoClient(); $db = $mongo->{"build-ap"}; // Add champions to database $champions = $db->{"STATIC.CHAMPIONS"}; $champions->drop(); $success = false; while (!$success) { $data = $api->getChampions(); $success = $api->getSuccess(); if (!$success) { $time->exceed(); } $time->delay(); } $document = json_decode($data); foreach ($document->{"data"} as $name => $data) { $champions->insert($data); } // Add items to database $items = $db->{"STATIC.ITEMS"};
echo "\t-i json file containing a list of matches\n"; echo "\t-t match type, either 'NORMAL_5X5' or 'RANKED_SOLO'\n"; echo "\t-v match game version, something like 5.11 or 5.14\n"; echo "example: php fetch-matches.php -i NA.json -t normal -v 5.11\n"; die; } if (!file_exists($opts["i"])) { echo "unable to locate '" . $opts["i"] . "'...\n"; die; } if (!preg_match('/(?:^|\\/)(\\w*)\\.(?:\\w*)$/', $opts["i"], $matches)) { echo "invalid filename format... expected {region}.json\n"; die; } $region = $matches[1]; $api = new RiotLeagueAPI($region, $league_api_key); $time = new RateLimit(); $mongo = new MongoClient(); $db = $mongo->{"build-ap"}; $collection_name = strtoupper($opts["t"] . "." . $opts["v"] . "." . $region); $collection = $db->{$collection_name}; $collection->createIndex(array('matchId' => 1)); $matches = json_decode(file_get_contents($opts["i"]), true); echo "retrieving {$collection_name}...\n"; $match_count = count($matches); for ($i = 0; $i < $match_count; $i++) { if ($collection->find(array('matchId' => $matches[$i]))->count() == 0) { $success = false; while (!$success) { $data = $api->getMatch($matches[$i]); $success = $api->getSuccess();