Created
September 10, 2010 00:57
-
-
Save nipotan/572863 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/perl | |
use strict; | |
use warnings; | |
use Net::Twitter; | |
use Config::Pit; | |
my $message = do { local $/; <STDIN> }; | |
my $header = parse_header($message); | |
exit 0 unless $header->{emailtype} eq 'is_following'; | |
exit 0 unless defined $header->{senderscreenname}; | |
my $config = pit_get("twitter.com", require => { | |
consumer_key => '', | |
consumer_secret => '', | |
access_token => '', | |
access_token_secret => '', | |
}); | |
my $twitter = Net::Twitter->new( | |
traits => [qw/API::REST OAuth/], | |
%$config, | |
); | |
eval { $twitter->create_friend($header->{senderscreenname}) }; | |
if ($@) { | |
warn $@; | |
exit 0 if $@ =~ /is already on your list/; | |
} | |
exit 0; | |
sub parse_header { | |
my $message = shift; | |
my %header_data = (); | |
while ($message =~ m{^X-Twitter(\w+):\s+(.+)}gm) { | |
my $key = $1; | |
my $val = $2; | |
$header_data{$key} = $val; | |
} | |
return \%header_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment