-
-
Save sugyan/718689 to your computer and use it in GitHub Desktop.
twitter streaming notification using notifo.com #notwife
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
#!/bin/sh | |
exec setuidgid sugyan multilog t n1 s1048576 . |
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
#!/bin/sh | |
export HOME=/home/sugyan | |
exec 2>&1 | |
exec \ | |
env PATH=/home/sugyan/perl5/perlbrew/bin:/home/sugyan/perl5/perlbrew/perls/current/bin:/home/sugyan/local/bin:/usr/local/bin:/bin:/usr/bin \ | |
/home/sugyan/git-clone/gist-718689/twitter-notifo.pl |
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/bin/env perl | |
use strict; | |
use warnings; | |
use AnyEvent::Twitter::Stream; | |
use Config::Pit; | |
use Net::Twitter::Lite; | |
use WebService::Notifo; | |
my $config = pit_get('twitter.com', require => { | |
consumer_key => 'consumer_key', | |
consumer_secret => 'consumer_secret', | |
token => 'token', | |
token_secret => 'token_secret', | |
}); | |
my $screen_name = do { | |
Net::Twitter::Lite->new( | |
%$config, | |
access_token => $config->{token}, | |
access_token_secret => $config->{token_secret}, | |
)->verify_credentials->{screen_name}; | |
}; | |
my $notifo = WebService::Notifo->new; | |
my $cv = AE::cv; | |
my $listener = AnyEvent::Twitter::Stream->new( | |
%$config, | |
method => 'userstream', | |
on_tweet => sub { | |
my ($tweet) = @_; | |
# Retweet | |
if (my $retweet = $tweet->{retweeted_status}) { | |
if ($retweet->{user}{screen_name} eq $screen_name) { | |
my $from = $tweet->{user}{screen_name}; | |
my $text = $retweet->{text}; | |
$notifo->send_notification(msg => "Retweet from \@$from: $text"); | |
} | |
} | |
# Mention | |
else { | |
for my $mention (@{ $tweet->{entities}{user_mentions} }) { | |
if ($mention->{screen_name} eq $screen_name) { | |
my $from = $tweet->{user}{screen_name}; | |
my $text = $tweet->{text}; | |
$notifo->send_notification(msg => "Mention from \@$from: $text"); | |
} | |
} | |
} | |
}, | |
on_event => sub { | |
my ($tweet) = @_; | |
my $event = $tweet->{event}; | |
my $from = $tweet->{source}{screen_name}; | |
my $target = $tweet->{target_object} ? $tweet->{target_object}{text} : ''; | |
$notifo->send_notification(msg => "$event from \@$from: $target"); | |
}, | |
on_connect => sub {}, | |
on_delete => sub {}, | |
on_friends => sub {}, | |
on_eof => sub { | |
warn "on_eof: @_"; | |
}, | |
on_error => sub { | |
warn "on_error: @_"; | |
$cv->send; | |
}, | |
); | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment