// Get all brackets that need to be updated $brackets = Api\Bracket::queryReturnAll(['state' => ['in' => [BS_NOMINATIONS, BS_ELIMINATIONS, BS_VOTING]]]); $bot = new Api\Reddit(RB_BOT); for ($i = 0, $count = count($brackets); $i < $count; $i++) { $bracket = $brackets[$i]; $cacheKey = 'CRON::reddit-poster_' . $bracket->id; $title = Api\Round::getBracketTitleForActiveRound($bracket); $oldTitle = Lib\Cache::Get($cacheKey); if ($title != $oldTitle) { $fullTitle = $bracket->name . ' - ' . $title; $url = $bracket->state == BS_NOMINATIONS ? 'nominate' : 'vote'; $message = '[Vote on today\'s round](http://animebracket.com/' . $url . '/' . $bracket->perma . ')' . PHP_EOL . PHP_EOL . '[View bracket results](http://animebracket.com/results/' . $bracket->perma . ')'; $out = null; echo 'Creating post for "', $fullTitle, '"... '; if ($bot->Submit($fullTitle, $message, 'r/AnimeBracket', 'self', $out)) { $bracket->externalId = $out->data->id; $bracket->sync(); echo $bracket->externalId; } else { if (isset($out->ratelimit)) { echo 'RATE LIMIT'; sleep(ceil($out->ratelimit)); $i--; } else { echo 'FAIL'; } } echo PHP_EOL; } Lib\Cache::Set($cacheKey, $title, 3600); }
<?php require 'config.php'; require 'lib/aal.php'; // Disable caching Lib\Cache::setDisabled(true); // Get all brackets that need to be updated $brackets = Api\Bracket::queryReturnAll(['advanceHour' => gmdate('G'), 'state' => ['in' => [BS_ELIMINATIONS, BS_VOTING]]]); if ($brackets && count($brackets)) { foreach ($brackets as $bracket) { echo 'Advancing ', $bracket->name, '...'; $bracket->advance(); Api\Bracket::getBracketByPerma($bracket->perma); echo 'DONE', PHP_EOL; } } // Reorder the brackets based upon participation Lib\Db::Query('CALL proc_UpdateBracketScores'); // Clean out old brackets Lib\Db::Query('CALL proc_CleanBrackets'); // Refresh caches Api\Bracket::getAll();