O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

Publishing Mindshare
This hack is based on Spidering Hack#49 and Google Hack #79. One of the things I always did to help keep track of Linux's popularity is to go to the local bookstore and see how many shelves were dedicated to Linux and compare this to Microsoft Server software. I've did this with web/non-web and Perl/Java as well. Now we can automate this with Amazon's API.

Contributed by:
[08/23/04 | Discuss (0) | Link to this hack]


There are a couple of approaches to this. I went with the simplest one. I used the Perl script at the end to identify how many books are there for the two topic I'm interested in. For example:

mindshare.pl Perl Python  
714 - Perl
275 - Python

There are limitations to this of course. Perl is older than python so this may not be a fair comparison. After all:

mindshare.pl Python Cobol
706 - Cobol
275 - Python

So this script may need to be tweaked depending on your need.

Possibilities could include:
1. books are weighted depending on their amazon rank
2. Only consider books written in the last few years.

Another idea might be to graph the number of books published each year for the topics you're interested in.

Here's the script:

#!/usr/bin/perl -w
# amazon_mindshare.cgi
# This implementation by Tommie Jones
# Based on an idea by Steven Johnson
# http://www.stevenberlinjohnson.com/movabletype/archives/000009.html

use lib qw(/usr/home/tj/public_html/modules);
use strict;
use LWP::Simple;
use XML::Simple;
use Data::Dumper;
my ($competitor1,$competitor2)=@ARGV;

# Your Amazon API developer's key
my $amazon_key='Put you key here';

if ($competitor1 and $competitor2) {
  my $request_tmpl="http://aws-beta.amazon.com/onca/xml?Service=AWSProductData&SubscriptionId=AMAZON_KEY&Operation=ItemSearch&SearchIndex=Books&Keywords=KEYWORDS";

  $request_tmpl=~ s/AMAZON_KEY/$amazon_key/g;
  my $request=$request_tmpl;
  $request=~ s/KEYWORDS/$competitor1/g;
  my $results_competitor1  = XMLin(get($request));

  $request=~ s/KEYWORDS/$competitor2/g;
  my $results_competitor2  = XMLin(get($request));
  my $competitor1_count=$results_competitor1->{Items}->{TotalResults};
  my $competitor2_count=$results_competitor2->{Items}->{TotalResults};

  print "$competitor1_count - $competitor1 \n";
  print "$competitor2_count - $competitor2 \n";

O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.