#!/usr/bin/perl

use Net::Blogger;
use common;

my $debug  = 1;
my $PROXY  = 'http://mala.homeip.net/blog/nucleus/xmlrpc/server.php';
my $BLOG   = 'mala::blog';
my $LOGIN  = 'B0Tbadmo';
my $PASS   = 'B0Tbadmo';

my $TITLE  = "Things I've learned from B-movies";
my $CATEG  = "bot";

#------------------------------------------------------------------
my $BADMOVIES_URL = 'http://www.badmovies.org/movies/';
my $LINK_FORMAT   = '/movies/.*?/index.html';
my @quotes;


my $idx_content = getpage ($BADMOVIES_URL);
print "Got page.\n" if $debug;
my @movies = exturl ($idx_content,$LINK_FORMAT,'',$BADMOVIES_URL);
my $movies_size = @movies;
my $randurl = $movies[rand($movies_size-1)];

my $mov_content = getpage($randurl);
print "Got movie.\n" if $debug;

if ($mov_content =~ /<title>\s*Review for (.*?)\s*\n/si){
	$title = $1; chomp $title;
}

if ($mov_content =~ /learned\.gif>(.*?)<\/font><br>/si){
	my $learned = $1;
	while ($learned =~ /10>\s*(.*?)\s*\n/gsi){
		push @quotes,$1;
	}
}

my $quote_size = @quotes;
my $quote = $quotes[rand($quote_size-1)];
$DATA  = qq|$quote<br>|;
$DATA .= qq|(<a href="$randurl">$title</a>)|;
#------------------------------------------------------------------

$blogger  = Net::Blogger->new(debug=>$debug);

$blogger->Proxy($PROXY);
$blogger->Username($LOGIN);
$blogger->Password($PASS);

my $blogid = $blogger->GetBlogId(blogname=>$BLOG);

$blogger->BlogId($blogid);

my $txt  = "<title>$TITLE</title>";
   $txt .= "<category>$CATEG</category>";
   $txt .= "$DATA";

my $id = $blogger->newPost(postbody=>\$txt,publish=>1) || die "Error: ".$b->LastError();


