Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Twib::CLI::StreamReader;
- use Mouse;
- with 'Twib::API::Role';
- use AnyEvent::Twitter::Stream;
- use DateTime::Format::Strptime;
- use Encode;
- use URI::Find;
- use utf8;
- has 'username' => ( is => 'rw', isa => 'Str', default => '' );
- has 'password' => ( is => 'rw', isa => 'Str', default => '' );
- has 'track' => ( is => 'rw', isa => 'Str', default => 'http,bit.ly' );
- no Mouse;
- sub run {
- my $self = shift;
- my $done = AnyEvent->condvar;
- my $guard = AnyEvent::Twitter::Stream->new(
- username => $self->username,
- password => $self->password,
- method => "filter",
- track => $self->track,
- on_tweet => sub {
- my $tweet = shift;
- if ( $tweet->{text} && $tweet->{text} =~ /[あ-んア-ン]/ ) {
- my @links;
- my $finder = URI::Find->new(
- sub {
- my $uri = shift;
- push ( @links, $uri->as_string );
- }
- );
- my $text = $tweet->{text};
- $finder->find( \$text );
- $self->create_post( $tweet, \@links );
- }
- },
- on_error => sub {
- my $error = shift;
- warn "ERROR: $error";
- $done->send;
- },
- on_eof => sub {
- $done->send;
- },
- );
- $done->recv;
- }
- #...
Add Comment
Please, Sign In to add comment