#!/usr/bin/perl ############################################################################# ## Bestzoniser - Show Amazon Bestseller Lists on Your Own Site ## This Script for Amazon.co.uk's Computers & Internet / Cyberculture / Wired Culture / Government ## Version 1.00 ## John Gotze - john@gotzespace.dk ## ## Original Program Name: maxcomm100.cgi version 1.00 ## http://www.computer-mentors.com/download.html ## Author : Ross Faulds (Checkpoint Computer Consultants Ltd) ## email : ross@checkpoint.demon.co.uk ## Copyright : Checkpoint Computer Consultants (1999) ## Date : 14/05/1999 ## ############################################################################# ## Installation Instructions ## ## Change the following variables ## ## $progname - set to the script's name ## $cgi-url - set to the path to your cgi-bin (ensure forward slash on end) ## $templatedir - set to the FULL path to the file. ## ## FTP the script into your cgi-bin directory. ## Set permissions so script is executable (for unix this should be 0755) ## ## Usage: ## Simply call the script with these parameters: ## bestzoniser.cgi?whichamazon=http%3A%2F%2Fwww.amazon.co.uk&mymode=first&tag=YOUR_AMAZON_ID ## (set you Amazon Associates ID) ############################################################################# use CGI; ##use CGI::Carp qw(fatalsToBrowser); use LWP::UserAgent; use URI::Escape; use HTTP::Request; use HTTP::Response; use Fcntl; ## Configuration area ## change these variables for your site. $progname="bestzoniser.cgi"; $cgi_url ="/books/"; ## path to your script directory (where bestzoniser.cgi is located) $templatedir = "/FULL_PATH/TO/YOUR/TEMPLATESDIR"; ## No trailing slash ## Main program $hot100_url = "/exec/obidos/cache/browse/computers---internet/cyberculture/wired-culture/government/list"; $hidden_type = "param(tag); $mode = $q->param(mode); my $url = $which_amazon . $hot100_url; $content = &get_amazon_page($url); &modify_content($content,$which_amazon); } else { $tag = $q->param(tag); $myurl = $q->param(myurl); $content = &get_amazon_page($myurl); &modify_content($content,$which_amazon); } sub get_amazon_page() { my $url = shift(@_); my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new(GET=> $url); my $response = $ua->request($req); if ($response->is_error()) { $response->error_as_HTML(); ## printf(" %s\n",$response->status_line); } $content = $response->content(); return $content; } sub page_header{ open (READIT, "$templatedir/header.html"); read (READIT, $header, 20000,0); close (READIT); print $header; } sub page_footer{ open (READIT,"$templatedir/footer.html"); read (READIT, $footer, 20000,0); close (READIT); return $footer; } sub modify_content { my $content = shift(@_); my $which_amazon = shift(@_); my $call_maxcomm100 = "$cgi_url$progname?whichamazon=http%3A%2F%2Fwww.amazon.co.uk&mymode=next&tag=$tag&myurl=http%3A%2F%2Fwww.amazon.co.uk"; $content =~ m/\
\Browse our most (.*)\
/sgi; $matched = $&; $matched =~ s/src=\"\/uk-covers/src=\"$which_amazon\/uk-covers/sgi; $matched =~ s/src=\"\/covers/src=\"$which_amazon\/covers/sgi; $matched =~ s/\"\/exec\/obidos/\"$which_amazon\/exec\/obidos/sgi; $matched =~ s/(ASIN\/)(.*?)(\/(.*?)\")/$1$2\/$tag\"/sgi; $matched =~ s/qid.*\"/$tag\"/sgi; $matched =~ s/\/o\//\//sgi; $matched =~ s/\