Twitterã¯ã©ã¤ã¢ã³ãã¢ããªã§ããããããã¹ã¯ãããéç¥æ©è½ããMacã®å ´åã¯Growlã§ã¢ã¤ã³ã³ã¨çºè¨ãåºãããã¾ãããã
å
æ¥TwitterのUser streams APIがついに一般公開されたããã§ãããã«ä¼´ã£ã¦CPANã¢ã¸ã¥ã¼ã«"AnyEvent::Twitter::Stream"ãã¢ãããã¼ãããã¾ããã
Tatsuhiko Miyagawa / AnyEvent-Twitter-Stream-0.20 - search.cpan.org
ãã£ãããªã®ã§ã¡ãã£ã¨ä½¿ã£ã¦ã¿ã¾ããã
åèï¼Twitterの新しいStreaming API「ChirpUserStreams」がすごすぎる件 - すぎゃーんメモ
#!/usr/bin/perl use strict; use warnings; use AnyEvent::HTTP; use AnyEvent::Twitter::Stream; use Config::Pit; use File::Temp; use Encode qw/encode_utf8 from_to/; use Log::Dispatch::DesktopNotification; my $config = pit_get('twitter.com', require => { consumer_key => 'consumer key', consumer_secret => 'consumer secret', token => 'access token', token_secret => 'access token secret', }); my $notify = Log::Dispatch::DesktopNotification->new( min_level => 'info', sticky => 0, ); my $cv = AE::cv; my $listener = AnyEvent::Twitter::Stream->new( %$config, method => 'userstream', on_tweet => sub { my ($tweet) = @_; my $user = $tweet->{user}{screen_name}; my $text = encode_utf8($tweet->{text} || ''); return unless $user && $text; my $image_url = $tweet->{user}{profile_image_url}; http_get $image_url, sub { my ($data, $headers) = @_; my ($suffix) = $image_url =~ /(\.[^\.]+)$/; my $fh = File::Temp->new( SUFFIX => $suffix, UNLINK => 1, ); print $fh $data; $notify->{title} = $user; $notify->{icon_file} = $fh->filename; from_to($text, 'MacRoman', 'utf8'); $notify->log( level => 'info', message => $text, ); }; }, ); $cv->recv;
streamingã§èªåã®followerãã¡ã®çºè¨ãåå¾ãããã¹ã¯ãããã«éç¥ãã¾ããããã¯ã°ã©ã¦ã³ãã§å®è¡ããã¦ããã°ããããããªãã§ãããããMacã®Growlã§ã¯ç¢ºèªæ¸ã¿ãLinuxã§ã¯åããã©ãããããã¾ãã*1ãWindowsã§ã¯ä½ãèµ·ãããªãããããªãããªã
OAuthèªè¨¼ã«å¿
è¦ãªæ
å ±ã¯Config::Pitã§èªã¿è¾¼ãã§ã¾ãã"on_tweet"ã§æ¬¡ã
ã¨åå¾ãããçºè¨ãããã·ã¥ãªãã¡ã¬ã³ã¹ã§åãåãã®ã§ãããããéç¥ã¸ããã£ãããªã®ã§Growlã«ã¢ã¤ã³ã³ã表示ãããããã¨æã£ãã®ã ãã©URLãæå®ãã¦ããã¡ãªãããªã®ã§AnyEvent::HTTPã§ãã¦ã³ãã¼ããã¦ãã¦tempfileã«æ¸ãè¾¼ãã§ãã¹ã渡ãããã«ãã(ãããæ¡å¼µåãã¤ãã¦ãªãã¨ãã¡ããã)ã$notifyã®titleãicon_fileãç´æ¥ä»£å
¥ã§æ¸ãæããã®ã¯è¡åæªããããããªããMacGrowlã使ã£ã¦æ¥æ¬èªã渡ãå ´åã¯ã¨ã³ã³ã¼ãããªãã ãããã©ããããããããã£ã¨ãã¾ãã§ããã®ããªã
*1:追è¨ï¼åããããã§ããid:punitanãããããã¨ããããã¾ãã http://d.hatena.ne.jp/punitan/20101002/1286048130