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; }
* in the queue by collect.php. **/ use OpenFuego\lib\DbHandle; use OpenFuego\app\Consumer; use OpenFuego\lib\Logger; 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__ . " consumer was terminated."); }); $dbh = new DbHandle(); $sql = "\nCREATE TABLE IF NOT EXISTS `openfuego_citizens` (\n `user_id` bigint(20) unsigned NOT NULL,\n `influence` tinyint(2) unsigned NOT NULL,\n PRIMARY KEY (`user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\nCREATE TABLE IF NOT EXISTS `openfuego_links` (\n `link_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\n `url` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n `first_seen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n `first_tweet` bigint(20) unsigned NOT NULL,\n `first_user` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n `first_user_id` bigint(20) unsigned DEFAULT NULL,\n `weighted_count` smallint(5) unsigned NOT NULL,\n `count` smallint(5) unsigned NOT NULL DEFAULT '1',\n `last_seen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`link_id`),\n UNIQUE KEY `url` (`url`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\nCREATE TABLE IF NOT EXISTS `openfuego_short_links` (\n `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\n `input_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `long_url` text COLLATE utf8_unicode_ci NOT NULL,\n `last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`input_url`),\n UNIQUE KEY `id` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\nCREATE TABLE IF NOT EXISTS `openfuego_tweets_cache` (\n `link_id` mediumint(8) unsigned NOT NULL,\n `id_str` bigint(20) unsigned NOT NULL,\n `screen_name` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n `text` varchar(140) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n `profile_image_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`link_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\nALTER TABLE `openfuego_tweets_cache`\n ADD CONSTRAINT `FK.openfuego_tweets_cache.link_id` FOREIGN KEY (`link_id`) REFERENCES `openfuego_links` (`link_id`) ON DELETE CASCADE ON UPDATE CASCADE;\n"; try { $sth = $dbh->prepare($sql); $sth->execute(); } catch (\PDOException $e) { die($e); } $dbh = NULL; $consumer = new Consumer(); $consumer->process(); exit;
use OpenFuego\app\Collector; use OpenFuego\lib\Logger; 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);