fakestream.php can now take --all option to pull the latest messages from multiple locally-authed accounts when generating simulated sitestreams info

This commit is contained in:
Brion Vibber 2010-11-02 16:43:01 -07:00
parent 445b306b54
commit a2f0f68d75

View File

@ -48,6 +48,8 @@ if (have_option('n')) {
$nickname = get_option_value('n'); $nickname = get_option_value('n');
} else if (have_option('nick')) { } else if (have_option('nick')) {
$nickname = get_option_value('nickname'); $nickname = get_option_value('nickname');
} else if (have_option('all')) {
$nickname = null;
} else { } else {
show_help($helptext); show_help($helptext);
exit(0); exit(0);
@ -82,25 +84,64 @@ function twitterAuthForUser(User $user)
*/ */
function dumpMessage($flink, $data) function dumpMessage($flink, $data)
{ {
$msg->for_user = $flink->foreign_id; $msg = prepMessage($flink, $data);
$msg->message = $data;
print json_encode($msg) . "\r\n"; print json_encode($msg) . "\r\n";
} }
if (have_option('all')) { function prepMessage($flink, $data)
throw new Exception('--all not yet implemented'); {
$msg->for_user = $flink->foreign_id;
$msg->message = $data;
return $msg;
} }
$user = User::staticGet('nickname', $nickname); if (have_option('all')) {
$auth = twitterAuthForUser($user); $users = array();
$flink = Foreign_link::getByUserID($user->id,
$flink = new Foreign_link();
$flink->service = TWITTER_SERVICE;
$flink->find();
while ($flink->fetch()) {
if (($flink->noticesync & FOREIGN_NOTICE_RECV) ==
FOREIGN_NOTICE_RECV) {
$users[] = $flink->user_id;
}
}
} else {
$user = User::staticGet('nickname', $nickname);
$users = array($user->id);
}
$output = array();
foreach ($users as $id) {
$user = User::staticGet('id', $id);
if (!$user) {
throw new Exception("No user for id $id");
}
$auth = twitterAuthForUser($user);
$flink = Foreign_link::getByUserID($user->id,
TWITTER_SERVICE); TWITTER_SERVICE);
$friends->friends = $auth->friendsIds(); $friends->friends = $auth->friendsIds();
dumpMessage($flink, $friends); dumpMessage($flink, $friends);
$timeline = $auth->statusesHomeTimeline(); $timeline = $auth->statusesHomeTimeline();
foreach ($timeline as $status) { foreach ($timeline as $status) {
dumpMessage($flink, $status); $output[] = prepMessage($flink, $status);
}
} }
usort($output, function($a, $b) {
if ($a->message->id < $b->message->id) {
return -1;
} else if ($a->message->id == $b->message->id) {
return 0;
} else {
return 1;
}
});
foreach ($output as $msg) {
print json_encode($msg) . "\r\n";
}