Bot-Twatterhose
view release on metacpan or search on metacpan
lib/Bot/Twatterhose.pm view on Meta::CPAN
} else {
# Updated status, all OK
say "Twatted: $reply";
exit 0;
}
} else {
if ($text =~ /^[[:ascii:]]+$/ and $text !~ /\n/ and $text !~ m[://]) {
$hailo->learn($text);
say sprintf "Got twat %d/%d: %s", $data->{count}, $self->limit, $text;
} else {
say sprintf "NOT twat %d/%d: %s", $data->{count}, $self->limit, $text;
}
}
};
$self->twatterhose($callback);
}
sub get_reply {
my ($self, $hailo) = @_;
while (1) {
my $reply = $hailo->reply();
return $reply if length $reply <= 140;
}
}
sub twatterhose {
my ($self, $callback) = @_;
my ($username, $password) = map { $self->$_ } qw(username password);
my $cmd = "curl -s http://stream.twitter.com/1/statuses/sample.json -u${username}:${password}";
open my $twitter, "$cmd |";
my $data = {};
while (my $line = <$twitter>) {
chomp $line;
my $twat = from_json($line);
$callback->($twat, $data);
}
}
__PACKAGE__->meta->make_immutable;
=head1 NAME
Bot::Twatterhose - Consume the Twitter firehose and babble to Twitter with L<Hailo>
=head1 SYNOPSIS
# Consume 500 tweets and twat one based on those
twatterhose --username someuser --password somepass --brain twatterhose.brn --limit 500
# Put this in cron, wait a few years and a cult will have formed
# around your bot:
*/30 * * * * (sleep $(($RANDOM % 3600))) && twatterhose --username someuser --password somepass --brain ~/twatterhose.brn
=head1 DESCRIPTION
Uses the L<twitter streaming
API|http://apiwiki.twitter.com/Streaming-API-Documentation> to get
tweets from the firehose, feeds those to L<Hailo> and tweets a random
permutation of the previous input to Twitter.
The author is trying to start a religion larger than L. Ron Hubbard's.
=head1 AUTHOR
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 0.648 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )