#!/usr/bin/perl
use strict;
use warnings;
use Config::Pit;
use AnyEvent::Twitter::Stream;
use Net::Twitter::Lite;
binmode STDOUT, ":utf8";
my $config = pit_get("nullpo-ga", require => {
"username" => "your username on twitter.com",
"password" => "your password on twitter.com"
});
my $nt = Net::Twitter::Lite->new(
username => $config->{username},
password => $config->{password},
);
my $done = AnyEvent->condvar;
my $streamer = AnyEvent::Twitter::Stream->new(
username => $config->{username},
password => $config->{password},
method => "track",
( track => 'NullPointerException' ),
on_tweet => sub {
my $tweet = shift;
print "$tweet->{user}{screen_name}: $tweet->{text}\n";
eval { $nt->update("\@$tweet->{user}{screen_name} Ga!!") };
},
on_error => sub {
my $error = shift;
warn "ERROR: $error";
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;
追記
miyagawaさんから返信のupdateでブロックしちゃうのでAnyEvent::Twitter使えば良いと教えて貰いました。
#!/usr/bin/perl
use strict;
use warnings;
use Config::Pit;
use AnyEvent::Twitter;
use AnyEvent::Twitter::Stream;
binmode STDOUT, ":utf8";
my $config = pit_get("nullpo-ga", require => {
"username" => "your username on twitter.com",
"password" => "your password on twitter.com"
}
);
my $done = AnyEvent->condvar;
my $twitty = AnyEvent::Twitter->new(
username => $config->{username},
password => $config->{password},
);
my $streamer = AnyEvent::Twitter::Stream->new(
username => $config->{username},
password => $config->{password},
method => "track",
( track => 'NullPointerException' ),
on_tweet => sub {
my $tweet = shift;
print "$tweet->{user}{screen_name}: $tweet->{text}\n";
$twitty->update_status("\@$tweet->{user}{screen_name} Ga!!", sub {
my ($twitty, $status, $js_status, $error) = @_;
if (defined $error) {
warn "ERROR: $error";
}
}
);
},
on_error => sub {
my $error = shift;
warn "ERROR: $error";
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;