#!/usr/bin/perl
use warnings;
use strict;
use CGI('div');
use XML::Simple;
use LWP::Simple;
my $amazon_dev_token = "AMAZON DEV TOKEN";
my $technorati_dev_token = "TECHNORATI DEV TOKEN";
my $result;
my $cgi = CGI::new();
my $name = $cgi->param('name');
print $cgi->header();
print $cgi->start_html(-title=>"Ego for $name",
-style=> {-src=>'http://www.benhammersley.com/style.css'});
print $cgi->start_div({-id=>'box'});
print $cgi->start_div({-id=>'head'});
print $cgi->h1(' ');
print $cgi->end_div({-id=>'head'});
print $cgi->start_div({-id=>'weblog'});
print $cgi->h2("Ego for $name");
print $cgi->p('This data is dynamically gathered from various web services, and so depends on those services actually working right now. If something seems broken, wait a few minutes and try again. More data sources to come, your mileage may vary, do not use while driving.');
print $cgi->p('Back to Ego Tools');
print $cgi->h3('Books listed at Amazon.co.uk');
my $amazon_result = get ("http://xml-eu.amazon.com/onca/xml3?t=webservices-20&dev-t=$amazon_dev_token&AuthorSearch=$name&mode=books-uk&type=heavy&page=1&f=xml&locale=uk");
my $amazon_result_xml = XMLin($amazon_result, forcearray=>1);
foreach my $result (@{$amazon_result_xml->{Details}}){
print $cgi->img({src=>"$result->{ImageUrlMedium}->[0]", alt=>"$result->{ProductName}->[0]", width=>'107', height=>'140', border=>'1', class=>'fright'});
print "Title: $result->{ProductName}->[0]";
print $cgi->br();
print "ISBN: $result->{Isbn}->[0]";
print $cgi->br();
print "List Price: $result->{ListPrice}->[0]";
print $cgi->br();
print "Amazon Price: $result->{OurPrice}->[0]";
print $cgi->br();
print $cgi->br();
print $cgi->br();
print $cgi->br();
print $cgi->br();
print $cgi->br();
print $cgi->br();
print $cgi->h3("People discussing this book on their weblog");
my $allconsuming_result = get("http://allconsuming.net/rest.cgi?action=GetWeblogMentionsForBook&isbn=$result->{Isbn}->[0]&days_back=999") or die "Could not connect to All Consuming";
my $allconsuming_result_xml = XMLin($allconsuming_result, forcearray=>1, suppressempty => 'There is no excerpt available');
foreach my $quotation (@{$allconsuming_result_xml->{weblogs}}){
my $technorati_result = get("http://api.technorati.com/bloginfo?url=$quotation->{url}&key=$technorati_dev_token") or die "Could not connect to Technorati";
my $technorati_result_xml = XMLin($technorati_result);
print '{url}".'">'.$technorati_result_xml->{document}->{result}->{weblog}->{name}.''." $quotation->{days_ago} days ago";
print $cgi->br();
print "$technorati_result_xml->{document}->{result}->{weblog}->{inboundlinks} inbound links";
print $cgi->br();
print "Last Updated: $technorati_result_xml->{document}->{result}->{weblog}->{lastupdate}";
print $cgi->blockquote("$quotation->{excerpt}");
}
}
print $cgi->end_div({-id=>'weblog'});
print $cgi->end_div({-id=>'box'});