stMind

about Tech, Computer vision and Machine learning

AnyEvent::Twitter::StreamをGrowl::AnyとMac::Growlで

AnyEvent::Twitter::Streamにあるサンプル(track.pl)を使ってツイートをGrowl::Any+Mac::Growlで通知するようにしてみた。

ほとんどtrack.plそのままだけど一応ソースは以下。
gist: 643223 - GitHub

#! /usr/bin/env perl

use strict;
use warnings;
use AnyEvent::Twitter::Stream;
use Config::Pit;
use Growl::Any;
use Encode;

my $config = pit_get('example.com', require => {
    consumer_key => 'your twitter consumer_key',
    consumer_secret => 'your twitter consumer_secret',
    token => 'your twitter access_token',
    token_secret => 'your twitter access_token_secret',
});

my $growl = Growl::Any->new;
$growl->register("Growl/Twitter", ["tweet"]);

my $done = AE::cv;

my $streamer; $streamer = AnyEvent::Twitter::Stream->new(
    consumer_key => $config->{consumer_key},
    consumer_secret => $config->{consumer_secret},
    token => $config->{token},
    token_secret => $config->{token_secret},
    method => 'userstream',
    on_tweet => sub {
        my $tweet = shift;
        $growl->notify(
            "tweet",
            encode_utf8($tweet->{user}{screen_name}),
            encode_utf8($tweet->{text}),
            $tweet->{user}{profile_image_url},
        );
    },
    on_error => sub {
        my $error = shift;
        warn "ERROR: $error";
        $done->send;
    },
    on_eof => sub {
        $done->send;
    },
);

$done->recv;