Skip to content

Instantly share code, notes, and snippets.

@otsune
Created February 11, 2010 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otsune/301754 to your computer and use it in GitHub Desktop.
Save otsune/301754 to your computer and use it in GitHub Desktop.
package AnyEvent::TumblrDashboard;
use base qw/AnyEvent::Twitter/;
sub receive_statuses_home {
my ($self, $weight) = @_;
weaken $self;
$self->{schedule}->{statuses_home} = {
wait => 0,
weight => $weight || 1,
request => sub { $self->_fetch_status_update ('home_timeline', @_) },
};
}
1;
package main;
use strict;
use warnings;
use AnyEvent;
#use AnyEvent::TumblrDashboard;
use Config::Pit;
use Encode qw/encode_utf8/;
my $config = pit_get("tumblr.com", require => {
"username" => "your username on tumblr",
"password" => "your password on tumblr"
});
my $tumblr = AnyEvent::TumblrDashboard->new(
username => $config->{username},
password => $config->{password},
base_url => 'http://tumblr.com',
);
$tumblr->reg_cb(
statuses_home => sub {
my ($tumblr, @statuses) = @_;
print_statuses(@statuses);
},
);
$tumblr->receive_statuses_home();
$tumblr->start;
my $cv = AnyEvent->condvar;
#my $w; $w = AnyEvent->io(
# fh => \*STDIN,
# poll => 'r',
# cb => sub {
# chomp(my $input = <STDIN>);
# $tumblr->update_status(decode_utf8($input), sub {
# my ($tumblr, $status, $js, $error) = @_;
# print "update!\n";
# });
# },
#);
my $w; $w = AnyEvent->timer(
after => 0,
interval => 5,
cb => sub {
# print "Time: ", AnyEvent->time, "\n";
},
);
$cv->recv;
sub print_statuses {
my @statuses = @_;
for my $status (map { $$_[0] } reverse @statuses) {
printf "%s:[%s]%s\n", (
scalar(localtime $status->{timestamp}),
$status->{screen_name},
encode_utf8($status->{text}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment