Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created November 3, 2009 14:41
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 sugyan/225087 to your computer and use it in GitHub Desktop.
Save sugyan/225087 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Twitter;
use Net::Twitter;
my %config = (
username => 'twitter username',
password => 'twitter password',
);
# make remaining_hits 0.
{
my $twitter = Net::Twitter->new(%config);
my $rate_limit_status = $twitter->rate_limit_status;
my $time_for_reset = $rate_limit_status->{reset_time_in_seconds} - time;
if ($time_for_reset < 200) {
sleep $time_for_reset;
}
for (1 .. $rate_limit_status->{remaining_hits}) {
$twitter->home_timeline;
print $twitter->rate_limit_status->{remaining_hits}, "\n";
sleep 1;
}
}
# main
{
local $AnyEvent::Twitter::DEBUG = 1;
my $twitty = AnyEvent::Twitter->new(%config);
$twitty->reg_cb(
error => sub {
my ($twitty, $error) = @_;
warn "error: $error\n";
},
statuses_friends => sub { },
);
$twitty->receive_statuses_friends;
$twitty->start;
my $cv = AE::cv;
my $w = AE::io *STDIN, 0, sub { $cv->send };
$cv->recv;
}
$ perl error.pl
TASK: statuses_friends => 1 | 1
MAXTASK: 1
error: error while fetching statuses for friends: 400 Bad Request
NEXT TICK IN -1257259142 seconds
TASK: statuses_friends => 1 | 1
MAXTASK: 1
error: error while fetching statuses for friends: 400 Bad Request
NEXT TICK IN -1257259142 seconds
TASK: statuses_friends => 1 | 1
MAXTASK: 1
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment