Created
March 18, 2011 03:04
-
-
Save turugina/875552 to your computer and use it in GitHub Desktop.
NHK_PRが「まろ」と呟いたらメールで通知するスクリプト(やっつけ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
#=============================== | |
my $consumer_key = ''; | |
my $consumer_secret = ''; | |
my $access_token = ''; | |
my $access_token_secret = ''; | |
my $email_address = ''; | |
#=============================== | |
use AnyEvent; | |
use AnyEvent::Twitter::Stream; | |
use Encode; | |
use Email::Send; | |
my $cv = AE::cv; | |
my $mailer = Email::Send->new({mailer => 'Sendmail'}); | |
my $listener = AnyEvent::Twitter::Stream->new( | |
consumer_key => $consumer_key, | |
consumer_secret => $consumer_secret, | |
token => $access_token, | |
token_secret => $access_token_secret, | |
method => "userstream", | |
delimited => 'none', | |
on_tweet => sub { | |
my $t = shift; | |
return if !defined $t->{text}; | |
if ( $t->{user}{screen_name} eq "NHK_PR" && index($t->{text}, 'まろ') >= 0 ) { | |
eval { | |
$mailer->send(encode('utf8', <<"EOM")); | |
To: $email_address | |
From: $email_address | |
Subject: \@NHK_PR said "$t->{text}" | |
at $t->{created_at}: | |
NHK_PR: $t->{text} | |
EOM | |
}; | |
warn $@ if $@; | |
} | |
}, | |
timeout => 60 | |
); | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment