Skip to content

Instantly share code, notes, and snippets.

@nipotan
Created September 10, 2010 00:57
Show Gist options
  • Save nipotan/572863 to your computer and use it in GitHub Desktop.
Save nipotan/572863 to your computer and use it in GitHub Desktop.
#!/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