From 75ed39a1c2f3bef31138441e3cc4b19434c06479 Mon Sep 17 00:00:00 2001 From: Gina Trapani Date: Sun, 14 Feb 2010 11:51:04 -0800 Subject: [PATCH] Started renaming replies mentions as per Twitter API updates --- common/class.Crawler.php | 38 ++++++++++++------------ common/class.TwitterAPIAccessorOAuth.php | 2 +- crawler/crawl.php | 4 ++- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/common/class.Crawler.php b/common/class.Crawler.php index b42a1ec23f..af5279480b 100644 --- a/common/class.Crawler.php +++ b/common/class.Crawler.php @@ -212,36 +212,36 @@ private function fetchAndAddTweetRepliedTo($tid, $td, $lurl, $fa) { $status_message = ""; } - function fetchInstanceUserReplies($lurl, $fa) { + function fetchInstanceUserMentions($lurl, $fa) { $status_message = ""; - // Get owner's replies + // Get owner's mentions if ($this->api->available_api_calls_for_crawler > 0) { - $got_newest_replies = false; + $got_newest_mentions = false; $continue_fetching = true; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) { - # Get the most recent replies - $replies = str_replace("[id]", $this->owner_object->username, $this->api->cURL_source['replies']); + # Get the most recent mentions + $mentions = str_replace("[id]", $this->owner_object->username, $this->api->cURL_source['mentions']); $args = array(); $args['count'] = 200; - if ($got_newest_replies) { - $this->last_page_fetched_replies++; - $args['page'] = $this->last_page_fetched_replies; + if ($got_newest_mentions) { + $this->last_page_fetched_mentions++; + $args['page'] = $this->last_page_fetched_mentions; } - list($cURL_status, $twitter_data) = $this->api->apiRequest($replies, $this->logger, $args); + list($cURL_status, $twitter_data) = $this->api->apiRequest($mentions, $this->logger, $args); if ($cURL_status > 200) { $continue_fetching = false; } else { try { $count = 0; $tweets = $this->api->parseXML($twitter_data); - if (count($tweets) == 0 && $got_newest_replies) {# you're paged back and no new tweets - $this->last_page_fetched_replies = 1; + if (count($tweets) == 0 && $got_newest_mentions) {# you're paged back and no new tweets + $this->last_page_fetched_mentions = 1; $continue_fetching = false; - $this->instance->is_archive_loaded_replies = true; - $status_message = 'Paged back but not finding new replies; moving on.'; + $this->instance->is_archive_loaded_mentions = true; + $status_message = 'Paged back but not finding new mentions; moving on.'; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; } @@ -255,32 +255,32 @@ function fetchInstanceUserReplies($lurl, $fa) { //expand and insert links contained in tweet $this->processTweetURLs($tweet, $lurl, $fa); if ($tweet['user_id'] != $this->owner_object->id) { //don't update owner info from reply - $u = new User($tweet, 'Replies'); + $u = new User($tweet, 'mentions'); $this->ud->updateUser($u, $this->logger); } } } - $status_message .= count($tweets)." replies found and $count saved"; + $status_message .= count($tweets)." mentions found and $count saved"; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; - $got_newest_replies = true; + $got_newest_mentions = true; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; - if ($got_newest_replies && $this->instance->is_archive_loaded_replies) { + if ($got_newest_mentions && $this->instance->is_archive_loaded_replies) { $continue_fetching = false; - $status_message .= 'Retrieved newest replies; Reply archive loaded; Stopping reply fetch.'; + $status_message .= 'Retrieved newest mentions; Reply archive loaded; Stopping reply fetch.'; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; } } catch(Exception $e) { - $status_message = 'Could not parse replies XML for $this->owner_object->username'; + $status_message = 'Could not parse mentions XML for $this->owner_object->username'; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; } diff --git a/common/class.TwitterAPIAccessorOAuth.php b/common/class.TwitterAPIAccessorOAuth.php index 982b6a5b1a..0dab0e8692 100644 --- a/common/class.TwitterAPIAccessorOAuth.php +++ b/common/class.TwitterAPIAccessorOAuth.php @@ -42,7 +42,7 @@ function prepAPI() { $search_format = 'atom'; # Define method paths ... [id] is a placeholder - $api_method = array("end_session"=>"/account/end_session", "rate_limit"=>"/account/rate_limit_status", "delivery_device"=>"/account/update_delivery_device", "location"=>"/account/update_location", "profile"=>"/account/update_profile", "profile_background"=>"/account/update_profile_background_image", "profile_colors"=>"/account/update_profile_colors", "profile_image"=>"/account/update_profile_image", "credentials"=>"/account/verify_credentials", "block"=>"/blocks/create/[id]", "remove_block"=>"/blocks/destroy/[id]", "messages_received"=>"/direct_messages", "delete_message"=>"/direct_messages/destroy/[id]", "post_message"=>"/direct_messages/new", "messages_sent"=>"/direct_messages/sent", "bookmarks"=>"/favorites/[id]", "create_bookmark"=>"/favorites/create/[id]", "remove_bookmark"=>"/favorites/destroy/[id]", "followers_ids"=>"/followers/ids/[id]", "following_ids"=>"/friends/ids/[id]", "follow"=>"/friendships/create/[id]", "unfollow"=>"/friendships/destroy/[id]", "confirm_follow"=>"/friendships/exists", "show_friendship"=>"/friendships/show", "test"=>"/help/test", "turn_on_notification"=>"/notifications/follow/[id]", "turn_off_notification"=>"/notifications/leave/[id]", "delete_tweet"=>"/statuses/destroy/[id]", "followers"=>"/statuses/followers/[id]", "following"=>"/statuses/friends/[id]", "friends_timeline"=>"/statuses/friends_timeline", "public_timeline"=>"/statuses/public_timeline", "replies"=>"/statuses/replies", "show_tweet"=>"/statuses/show/[id]", "post_tweet"=>"/statuses/update", "user_timeline"=>"/statuses/user_timeline/[id]", "show_user"=>"/users/show/[id]"); + $api_method = array("end_session"=>"/account/end_session", "rate_limit"=>"/account/rate_limit_status", "delivery_device"=>"/account/update_delivery_device", "location"=>"/account/update_location", "profile"=>"/account/update_profile", "profile_background"=>"/account/update_profile_background_image", "profile_colors"=>"/account/update_profile_colors", "profile_image"=>"/account/update_profile_image", "credentials"=>"/account/verify_credentials", "block"=>"/blocks/create/[id]", "remove_block"=>"/blocks/destroy/[id]", "messages_received"=>"/direct_messages", "delete_message"=>"/direct_messages/destroy/[id]", "post_message"=>"/direct_messages/new", "messages_sent"=>"/direct_messages/sent", "bookmarks"=>"/favorites/[id]", "create_bookmark"=>"/favorites/create/[id]", "remove_bookmark"=>"/favorites/destroy/[id]", "followers_ids"=>"/followers/ids/[id]", "following_ids"=>"/friends/ids/[id]", "follow"=>"/friendships/create/[id]", "unfollow"=>"/friendships/destroy/[id]", "confirm_follow"=>"/friendships/exists", "show_friendship"=>"/friendships/show", "test"=>"/help/test", "turn_on_notification"=>"/notifications/follow/[id]", "turn_off_notification"=>"/notifications/leave/[id]", "delete_tweet"=>"/statuses/destroy/[id]", "followers"=>"/statuses/followers/[id]", "following"=>"/statuses/friends/[id]", "friends_timeline"=>"/statuses/friends_timeline", "public_timeline"=>"/statuses/public_timeline", "mentions"=>"/statuses/mentions", "show_tweet"=>"/statuses/show/[id]", "post_tweet"=>"/statuses/update", "user_timeline"=>"/statuses/user_timeline/[id]", "show_user"=>"/users/show/[id]"); # Construct cURL sources foreach ($api_method as $key=>$value) { diff --git a/crawler/crawl.php b/crawler/crawl.php index 3f410448a1..35cf354adf 100644 --- a/crawler/crawl.php +++ b/crawler/crawl.php @@ -31,7 +31,9 @@ $crawler->fetchInstanceUserTweets($lurlapi, $flickrapi); - $crawler->fetchInstanceUserReplies($lurlapi, $flickrapi); + //TODO: Get retweeted_by_me and merge into user timeline to match up total tweets + + $crawler->fetchInstanceUserMentions($lurlapi, $flickrapi); $crawler->fetchInstanceUserFriends();