X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2Fdaemons%2Ftwitterstatusfetcher.php;h=7860a1fedf3b0d2086c82d4ca714835b17434856;hb=d9b35208ecda59292680fb55e38c56b2831d5366;hp=9298d9e3a1cd5543d05d5c49e20cb5e1bd8f7c00;hpb=9a590e0843063e9ac43f6372d55d6a0941764eab;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php old mode 100755 new mode 100644 index 9298d9e3a1..7860a1fedf --- a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php +++ b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php @@ -23,7 +23,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); // 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 +define('POLL_INTERVAL', 70); // in seconds, Twitter API v1.1 says 15 calls every 15 mins $shortoptions = 'di::'; $longoptions = array('id::', 'debug'); @@ -36,11 +36,10 @@ Batch script for retrieving Twitter messages from foreign service. END_OF_TRIM_HELP; -require_once INSTALLDIR . '/scripts/commandline.inc'; +require_once INSTALLDIR . '/scripts/commandline.inc.php'; require_once INSTALLDIR . '/lib/common.php'; require_once INSTALLDIR . '/lib/daemon.php'; -require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; -require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; +require_once dirname(__DIR__) . '/twitter.php'; /** * Fetch statuses from Twitter @@ -136,7 +135,8 @@ class TwitterStatusFetcher extends ParallelizingDaemon // a new connection if there isn't one already $conn = &$flink->getDatabaseConnection(); - $this->getTimeline($flink); + $this->getTimeline($flink, 'home_timeline'); + $this->getTimeline($flink, 'mentions_timeline'); $flink->last_friendsync = common_sql_now(); $flink->update(); @@ -149,64 +149,68 @@ class TwitterStatusFetcher extends ParallelizingDaemon unset($_DB_DATAOBJECT['CONNECTIONS']); } - function getTimeline($flink) + function getTimeline($flink, $timelineUri = 'home_timeline') { if (empty($flink)) { - common_log(LOG_WARNING, $this->name() . + common_log(LOG_ERR, $this->name() . " - Can't retrieve Foreign_link for foreign ID $fid"); return; } - common_debug($this->name() . ' - Trying to get timeline for Twitter user ' . - $flink->foreign_id); + common_debug($this->name() . ' - Trying to get ' . $timelineUri . + ' timeline for Twitter user ' . $flink->foreign_id); $client = null; if (TwitterOAuthClient::isPackedToken($flink->credentials)) { $token = TwitterOAuthClient::unpackToken($flink->credentials); $client = new TwitterOAuthClient($token->key, $token->secret); - common_debug($this->name() . ' - Grabbing friends timeline with OAuth.'); + common_debug($this->name() . ' - Grabbing ' . $timelineUri . ' timeline with OAuth.'); } else { - common_debug("Skipping friends timeline for $flink->foreign_id since not OAuth."); + common_log(LOG_ERR, "Skipping " . $timelineUri . " timeline for " . + $flink->foreign_id . " since not OAuth."); } $timeline = null; - $lastId = Twitter_synch_status::getLastId($flink->foreign_id, 'home_timeline'); + $lastId = Twitter_synch_status::getLastId($flink->foreign_id, $timelineUri); - common_debug("Got lastId value '{$lastId}' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'"); + common_debug("Got lastId value '" . $lastId . "' for foreign id '" . + $flink->foreign_id . "' and timeline '" . $timelineUri. "'"); try { - $timeline = $client->statusesHomeTimeline($lastId); + $timeline = $client->statusesTimeline($lastId, $timelineUri); } catch (Exception $e) { - common_log(LOG_WARNING, $this->name() . - ' - Twitter client unable to get friends timeline for user ' . - $flink->user_id . ' - code: ' . - $e->getCode() . 'msg: ' . $e->getMessage()); + common_log(LOG_ERR, $this->name() . + ' - Unable to get ' . $timelineUri . ' timeline for user ' . $flink->user_id . + ' - code: ' . $e->getCode() . 'msg: ' . $e->getMessage()); } if (empty($timeline)) { - common_log(LOG_WARNING, $this->name() . " - Empty timeline."); + common_log(LOG_DEBUG, $this->name() . " - Empty '" . $timelineUri . "' timeline."); return; } - common_debug(LOG_INFO, $this->name() . ' - Retrieved ' . sizeof($timeline) . ' statuses from Twitter.'); + common_log(LOG_INFO, $this->name() . + ' - Retrieved ' . sizeof($timeline) . ' statuses from ' . $timelineUri . ' timeline' . + ' - for user ' . $flink->user_id); - $importer = new TwitterImport(); - - // Reverse to preserve order - - foreach (array_reverse($timeline) as $status) { - $notice = $importer->importStatus($status); - - if (!empty($notice)) { - Inbox::insertNotice($flink->user_id, $notice->id); + if (!empty($timeline)) { + $qm = QueueManager::get(); + + // Reverse to preserve order + foreach (array_reverse($timeline) as $status) { + $data = array( + 'status' => $status, + 'for_user' => $flink->foreign_id, + ); + $qm->enqueue($data, 'tweetin'); } - } - if (!empty($timeline)) { - Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $timeline[0]->id); - common_debug("Set lastId value '{$timeline[0]->id}' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'"); + $lastId = twitter_id($timeline[0]); + Twitter_synch_status::setLastId($flink->foreign_id, $timelineUri, $lastId); + common_debug("Set lastId value '$lastId' for foreign id '{$flink->foreign_id}' and timeline '" . + $timelineUri . "'"); } // Okay, record the time we synced with Twitter for posterity @@ -232,5 +236,5 @@ if (have_option('d') || have_option('debug')) { $debug = true; } -$fetcher = new TwitterStatusFetcher($id, 60, 2, $debug); +$fetcher = new TwitterStatusFetcher($id, POLL_INTERVAL, MAXCHILDREN, $debug); $fetcher->runOnce();