Skip to content

Instantly share code, notes, and snippets.

@mostlyfine
Created February 16, 2012 02:23
Show Gist options
  • Select an option

  • Save mostlyfine/1841062 to your computer and use it in GitHub Desktop.

Select an option

Save mostlyfine/1841062 to your computer and use it in GitHub Desktop.
AnyEvent::Twitter::Stream sample
use strict;
use warnings;
use utf8;
use AnyEvent::Twitter::Stream;
use Log::Minimal;
$Log::Minimal::AUTODUMP=1;
$Log::Minimal::COLOR=1;
my $config_file = 'twitter.conf';
my $config = do $config_file or die qq/Can't load $config_file : $!$@/;
my $done = AnyEvent->condvar;
my $listener = AnyEvent::Twitter::Stream->new(
token => $config->{token},
token_secret => $config->{token_secret},
consumer_key => $config->{consumer_key},
consumer_secret => $config->{consumer_secret},
method => $config->{method} || 'filter',
track => $config->{keyword},
timeout => 300,
on_tweet => sub {
my $tweet = shift;
infof($tweet->{user}{screen_name}.' : '.$tweet->{text});
},
on_error => sub {
my $error = shift;
warnf($error);
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment