Skip to content

Commit

Permalink
Started renaming replies mentions as per Twitter API updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Feb 14, 2010
1 parent 5861c79 commit 75ed39a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
38 changes: 19 additions & 19 deletions common/class.Crawler.php
Expand Up @@ -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 = "";
}
Expand All @@ -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 = "";
}
Expand Down
2 changes: 1 addition & 1 deletion common/class.TwitterAPIAccessorOAuth.php
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion crawler/crawl.php
Expand Up @@ -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();

Expand Down

0 comments on commit 75ed39a

Please sign in to comment.