-
-
Save soh335/1197034 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 AnyEvent::WebService::Notifo; | |
my $twitter_config = pit_get('twitter.com', require => { | |
consumer_key => 'consumer_key', | |
consumer_secret => 'consumer_secret', | |
token => 'token', | |
token_secret => 'token_secret', | |
}); | |
my $notifo_config = pit_get('notifo.com', require => { | |
user => 'user', | |
api_key => 'api_key', | |
}); | |
my $screen_name = do { | |
Net::Twitter::Lite->new( | |
%$twitter_config, | |
access_token => $twitter_config->{token}, | |
access_token_secret => $twitter_config->{token_secret}, | |
)->verify_credentials->{screen_name}; | |
}; | |
my $notifo = AnyEvent::WebService::Notifo->new( | |
%$notifo_config | |
); | |
my $cv = AE::cv; | |
my $listener = AnyEvent::Twitter::Stream->new( | |
%$twitter_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", cb => \¬ifo_cb); | |
} | |
} | |
# 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", cb => \¬ifo_cb); | |
} | |
} | |
} | |
}, | |
on_event => sub { | |
my ($tweet) = @_; | |
my $event = $tweet->{event}; | |
my $from = $tweet->{source}{screen_name}; | |
my $target = $tweet->{target_object} ? $tweet->{target_object}{text} : ''; | |
return if $from eq $screen_name; | |
$notifo->send_notification(msg => "$event from \@$from: $target", cb => \¬ifo_cb); | |
}, | |
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; | |
sub notifo_cb { | |
my $res = shift; | |
unless ( $res->{http_response_code} =~ /^2/ ) { | |
warn $res->{http_status_line}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment