Created
April 23, 2010 03:26
-
-
Save hokaccha/376143 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/bin/env perl | |
### sugyanのtweetを自動でfavるscript | |
use strict; | |
use warnings; | |
use AnyEvent::HTTP 'http_request'; | |
use Config::Pit 'pit_get'; | |
use Encode 'encode_utf8'; | |
use JSON::XS 'decode_json'; | |
use LWP::UserAgent; | |
use MIME::Base64 'encode_base64'; | |
my $config = pit_get( | |
"twitter.com", | |
require => { | |
username => "your username on Twitter", | |
password => "your password on Twitter", | |
} | |
); | |
my $auth_header = HTTP::Headers->new( | |
Authorization => "Basic " . encode_base64(join ':', @$config{qw/username password/}), | |
); | |
my $res = LWP::UserAgent->new( | |
default_headers => $auth_header, | |
)->get('http://twitter.com/account/verify_credentials.json'); | |
my $self_id = decode_json($res->content)->{id}; | |
my $callback = sub { | |
my (undef, $json) = @_; | |
return if $json->{event}; | |
return if $json->{user} && $json->{user}{screen_name} ne 'sugyan'; | |
return unless $json->{id}; | |
http_request( | |
POST => 'http://twitter.com/favourings/create/'.$json->{id}.'.json', | |
headers => $auth_header, | |
sub {}, | |
); | |
}; | |
my $cv = AE::cv; | |
http_request( | |
GET => 'http://chirpstream.twitter.com/2b/user.json', | |
headers => $auth_header, | |
want_body_handle => 1, | |
sub { | |
shift->on_read(sub { shift->push_read( json => $callback ); }); | |
} | |
); | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment