I made this robot, at and for coffe shops or other public places with wifi. You can take him there and whenever anyone tweets his name, it will read the message from your laptops speakers...yes yes I know, ignore the man behind the curtains. This will only work on mac os x right now, as it uses the say command. If there is an equivelent on linux you can just plug the command name in $say near the bottom. If you have windows you can execute a little vbscript here that will do the same thing. So what I do is tweet things like "I want a coffee" for places like the coffeshop down the road and for places like cafe coco I crank it up with, "Will you buy me a beer". As always make sure any modules you don't have are install via cpan or activestate's ppm utility if you have trouble with cpan.
i.e. A tweet like this:
@beerbotprime Buy me a beer
will make beerbotprime say buy me a beer, no matter what account it is tweeted from
he also moves his hand
use Sys::Hostname;
use strict;
use warnings;
use LEGO::NXT;
use LEGO::NXT::Constants qw(:DEFAULT);
use LEGO::NXT::MacBlueComm;
use Net::Twitter;
use Date::Format;
my $dev = new LEGO::NXT::MacBlueComm('/dev/tty.NXT-DevB');
my $bt = new LEGO::NXT( $dev );
my $speed = 100;
my $tachoticks = 360;
my $tailFtac = 100;
my $tailBtac = 100;
my $tailSpeed = 100;
my $tailBSpeed = 100;
my $backSpeed = 100;
my @names = ('New Tweet');
my $bob = "test";
my $tail = "tail";
my $retract = "retract";
my $say;
my $tweet = Net::Twitter->new( username=>'beerbotprime', password=>'insertyourpassword' );
print "logged in? \n";
my $last_id = undef;
my $switch = 0;
while(1){
my @tt = ();
if($last_id){
@tt = $tweet->friends_timeline({count => 5, since_id => $last_id });
}else{
@tt = $tweet->friends_timeline({count => 5 });
}
foreach my $t (@{$tt[0]}){
my $target = $t->{text};
if($target =~ m/beerbotprime/i){
$say = `say $'`;
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_A, $speed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tachoticks );
$bt->keep_alive($NXT_NORET);
printf("%s: %s\n", $t->{user}{screen_name}, $t->{text});
print "sleep 4\n";
sleep(4);
}
$switch = 0;
print "sleep 4\n";
sleep(4);
}
}
exit;
No comments:
Post a Comment