$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(); if (!$success) { $time->exceed(); } $time->delay(); } $document = json_decode($data); $collection->remove(array('matchId' => $document->matchId)); $collection->insert($document); echo $i + 1 . "/{$match_count} processed...\r"; } else { echo $i + 1 . "/{$match_count} skipped...\r"; } } echo "\n";