stMind

You'll never blog alone

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

AnyEvent::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;