#!/usr/bin/perl -w
use strict;
use warnings;
use Orkut;

$|=1;
use Dumpvalue;
my $d= new Dumpvalue;

sub random {
    my ($n)= @_;
    while(1) {
        my $r= int(rand($n));
        return $r if ($r<$n);
    }
}

my $fn= shift || die "no filename specified\n";
my $fh= IO::File->new($fn, "r") or die "$fn: $!\n";
my @list= map { s/\s//g; $_ } <$fh>;
$fh->close();

while (@list) {
    my $nr= int(random(30)+20);
    $nr= @list if ($nr>@list);

    DownloadIdList(@list[0..$nr-1]);
    @list= @list[$nr..$#list];
}
exit(0);
sub DownloadIdList {
    my $o= Orkut->new(OrkutCredentials);

    print "downloading ", scalar @_, " ids\n";

    $o->GetFriendsList($_) for (@_);

    if ($o->{loggedin}) {
        print "sleeping\n";
        sleep(rand(120)+240);
    }
}

