#!/usr/bin/perl -w # Based on example in Oreilly "Amazon Hacks" book. use warnings; use strict; use CGI; use URI::Escape; use HTTP::Cookies; use LWP::UserAgent; # Set your associates account info. my $email = 'your@email.com'; my $pass = 'your_password'; my $aftag = 'your_affiliate_tag'; # Create a user agent object. # and fake the agent string. my $ua = LWP::UserAgent->new; $ua->agent("(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"); $ua->cookie_jar({}); # in-memory cookie jar. my @MMMS= qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @time = localtime(time-(88000*2)); # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = my $yyyy=1900+$time[5]; #"2004";#5 my $mmm =$MMMS[$time[4]];#"Apr";#4 my $dd =$time[3];#"13"; #3 # Request earning reports, logging in as one pass. my $rpturl = "https://associates.amazon.com/exec/panama/login/". "attempt/customer/associates/no-customer-id/25/". "associates/resources/reporting/earnings/"; my $rptreq = HTTP::Request->new(POST => $rpturl); my $rptdata = "report-type=shipments-by-item". # get individual items "&date-selection=date-range". # all earnings this quarter "&begin-month=Oct". "&begin-day=01". "&begin-year=2003". "&end-month=$mmm". "&end-day=$dd". "&end-year=$yyyy". "&login_id=".uri_escape($email). # our email address. "&login_password=".uri_escape($pass). # and password. "&submit.download=Download my report". # get downloadble. "&enable-login-post=true"; # login and post at once. $rptreq->content_type('application/x-www-form-urlencoded'); $rptreq->content($rptdata); my $report = $ua->request($rptreq); print CGI::header(); # Uncomment the following line to see # the report if you need to debug #print $report->content; # Set the report to array. my @lines = split(/\n/, $report->content); # Get the time period. my @fromdate = split(/\t/, $lines[1]); my @todate = split(/\t/, $lines[2]); my $from = $fromdate[1]; my $to = $todate[1]; # Print header... print qq{ Everyday Systems: Amazon Purchases

Amazon.com Items Purchased Through Everyday Systems Sites

from $from to $to

}; print qq{

Instead of placing obnoxious ads for products that some advertiser has decided you should buy, I've just provided a discreet handful of buy anything from amazon.com links throughout the everyday systems sites. Here are the results. Two things to note:

  1. I am a terrible businessman. In over six months I've recouped maybe 3 days operating expenses.
  2. The informational byproducts of even a terrible business are fascinating and perhaps even useful (though not necessarily to me). The items in the list below may actually be of interest to future visitors to everydaysystems.com. In a way, the list itself is a form of super directed advertising. At the moment, this assertion may seem a little crazy, but it will become more true as the list grows longer.

So if you're willing to believe #2, have a look at links below and help me remedy #1. I get an even larger cut for directly linked purchases.

Items are sorted by count (the number of times someone has purchased the item) and then by "my revenue" (the total dollar amount I have received for all purchases the item). Purchases are added when they ship, so don't get excited if you buy something and it doesn't show up here right away. This page automatically connects to amazon.coms database, so if you have nothing better to do, hit reload a lot, and eventually it will change.

Perl wonks may admire the totally uncommented and hacked together source code for this script here. It's based on an example in O'Reilly's excellent Amazon Hacks book.

}; # Loop through the # rest of the report splice(@lines,0,5); my %items; my $total_my_revenue; my $total_amazon_revenue; my $total_items; foreach my $line (@lines) { my @fields = split(/\t/, $line); my $asin = $fields[2]; $items{$asin}->{title} = $fields[1]; $items{$asin}->{edition} = $fields[4]; $items{$asin}->{count} += $fields[8]; $total_items++; my $my_revenue = $fields[-1]; $my_revenue =~ s/\$//; $items{$asin}->{my_revenue} += $my_revenue; $total_my_revenue+=$my_revenue; } print ""; print qq[]; for my $asin (sort {$items{$b}->{count} <=> $items{$a}->{count} || $items{$b}->{my_revenue} <=> $items{$a}->{my_revenue}} keys %items){ # Format items as HTML for display print qq[]; print qq[]; print qq[]; print qq[]; print qq[]; print qq[]; } print qq{}; print "
TitleEditionCountMy Revenue
$items{$asin}->{title}$items{$asin}->{edition}$items{$asin}->{count}\$$items{$asin}->{my_revenue}
Totals:$total_items\$$total_my_revenue
"; print qq{

 © 2004 Reinhard Engels, All Rights Reserved.

Valid XHTML 1.0!

}; print "";