* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Abort if called from a web server
-if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
-}
-
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
-define('LACONICA', true);
// Tune number of processes and how often to poll Twitter
// XXX: Should these things be in config.php?
define('MAXCHILDREN', 2);
define('POLL_INTERVAL', 60); // in seconds
-// Uncomment this to get useful logging
-// define('SCRIPT_DEBUG', true);
+$shortoptions = 'di::';
+$longoptions = array('id::', 'debug');
-// Preset the server at the command line
+$helptext = <<<END_OF_TRIM_HELP
+Batch script for retrieving Twitter messages from foreign service.
-$server = ($argc > 2) ? $argv[2] : null;
-$path = ($argc > 3) ? $argv[3] : null;
+ -i --id Identity (default 'generic')
+ -d --debug Debug (lots of log output)
-require_once INSTALLDIR . '/lib/common.php';
+END_OF_TRIM_HELP;
+
+require_once INSTALLDIR .'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/daemon.php';
/**
{
private $_children = array();
+ function __construct($id=null, $daemonize=true)
+ {
+ parent::__construct($daemonize);
+
+ if ($id) {
+ $this->set_id($id);
+ }
+ }
+
/**
* Name of this daemon
*
function name()
{
- return ('twitterstatusfetcher.generic');
+ return ('twitterstatusfetcher.'.$this->_id);
}
/**
function run()
{
+ if (defined('SCRIPT_DEBUG')) {
+ common_debug($this->name() .
+ ': debugging log output enabled.');
+ }
+
do {
$flinks = $this->refreshFlinks();
$notice->rendered = common_render_content($notice->content, $notice);
$notice->source = 'twitter';
$notice->reply_to = null; // XXX lookup reply
- $notice->is_local = NOTICE_GATEWAY;
+ $notice->is_local = Notice::GATEWAY;
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
}
}
-ini_set("max_execution_time", "0");
-ini_set("max_input_time", "0");
-set_time_limit(0);
-mb_internal_encoding('UTF-8');
declare(ticks = 1);
-$fetcher = new TwitterStatusFetcher();
+if (have_option('i')) {
+ $id = get_option_value('i');
+} else if (have_option('--id')) {
+ $id = get_option_value('--id');
+} else if (count($args) > 0) {
+ $id = $args[0];
+} else {
+ $id = null;
+}
+
+if (have_option('d') || have_option('debug')) {
+ define('SCRIPT_DEBUG', true);
+}
+
+$fetcher = new TwitterStatusFetcher($id);
$fetcher->runOnce();