public function populate($authorities, $min_influence = 1) { if (count($authorities) > 15) { $error_message = __METHOD__ . " failed. The maximum number of authorities is 15. Dying."; Logger::fatal($error_message); die($error_message); } $owner_screen_name = \OpenFuego\TWITTER_SCREEN_NAME; $twitter = new TwitterHandle(); $authorities = implode(',', $authorities); $authorities = str_replace('@', '', $authorities); $authorities = $twitter->get('users/lookup', array('screen_name' => $authorities)); foreach ($authorities as $authority) { $authorities_ids[] = $authority['id_str']; } $universe_ids = $authorities_ids; foreach ($authorities as $authority) { $authority_friends_ids = $twitter->get('friends/ids', array('screen_name' => $authority['screen_name'])); if ($twitter->http_code != 200) { $error_message = __METHOD__ . " failed, Twitter error {$twitter->http_code}. Dying."; Logger::fatal($error_message); die; } $authority_friends_ids = $authority_friends_ids['ids']; $universe_ids = array_merge($universe_ids, $authority_friends_ids); // append more ids to universe } $universe_ids_sorted = $this->array_most_common($universe_ids); unset($authority_friends_ids, $owner_screen_name, $twitter, $universe_ids); $dbh = self::getDbh(); $dbh->exec("TRUNCATE TABLE openfuego_citizens;"); $sql = "INSERT INTO openfuego_citizens (user_id, influence) VALUES (:user_id, :influence);"; $sth = self::$dbh->prepare($sql); foreach ($universe_ids_sorted as $key => $value) { try { $sth->bindParam('user_id', $key, \PDO::PARAM_INT); $sth->bindParam('influence', $value, \PDO::PARAM_INT); $sth->execute(); } catch (\PDOException $e) { Logger::fatal($e); die; } } return TRUE; }
use OpenFuego\lib\TwitterHandle; if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { die(__NAMESPACE__ . ' requires PHP 5.3.0 or higher.'); } if (php_sapi_name() != 'cli') { die('This script must be invoked from the command line.'); } if (!defined('OPENFUEGO') && function_exists('pcntl_fork')) { $error_message = "\n" . 'Do not run this script directly. Run fetch.php to start.' . "\n\n"; die($error_message); } require_once __DIR__ . '/init.php'; register_shutdown_function(function () { Logger::fatal(__NAMESPACE__ . " collector was terminated."); }); $twitter = new TwitterHandle(); $twitter->get("account/verify_credentials", array("include_entities" => 0, "skip_status" => 1)); if ($twitter->http_code !== 200) { $error_message = "Cannot continue. Your Twitter credentials appear to be invalid. Error code {$twitter->http_code}"; Logger::info($error_message); die($error_message); } unset($twitter_handle); $authorities = unserialize(\OpenFuego\AUTHORITIES); $universe = new Universe(); /** The next line is commented out by default. * Uncomment it to repopulate the universe on each fetch. */ // $universe->populate($authorities, 1); $citizens = $universe->getCitizens(1); if (!$citizens) { $universe->populate($authorities, 1);