Mercurial > hg > ywww
diff xml/amazonBookSearch.php @ 6:077b0a0a3e6d
remaining originals according to dependency walk
author | Robert Boland <robert@markup.co.uk> |
---|---|
date | Thu, 16 Feb 2017 22:29:02 +0000 |
parents | |
children | ae1459564f66 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/amazonBookSearch.php Thu Feb 16 22:29:02 2017 +0000 @@ -0,0 +1,98 @@ +<?php + +$Adefault=array( + 'language' =>'en', //what language to render the page in + 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us + 'page' =>1, //first page to show (we are counting from 1 not 0) + 'operation' =>'ItemSearch', //what to do? //ItemSearch + 'searchindex' =>'Books', //what product category for search? + 'searchparameter' =>'Keywords', //what kind of search? + 'searchparameterdata'=>'Machiavelli', //what to search for? + //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' + 'show_url' =>false, //debug: show XML request url to be send to Amazon? +); + +$Aassociates_id=array( + 'uk' => 'bookwhack-21', + 'us' => 'your02b-20', + 'ca' => 'book009-20', + 'de' => 'book04c-21', + 'fr' => 'book07f-21', +); + +$Aserver=array( + 'ca' => array( + 'ext' => 'ca' , //Canadian normal server + 'nor' => 'http://www.amazon.ca' , //Canadian normal server + 'xml' => 'http://xml.amazon.com' , //Canadian xml server + ), + 'de' => array( + 'ext' => 'de' , //German normal server + 'nor' => 'http://www.amazon.de' , //German normal server + 'xml' => 'http://xml-eu.amazon.com', //German xml server + ), + 'fr' => array( + 'ext' => 'fr' , //French normal server + 'nor' => 'http://www.amazon.fr' , //French normal server + 'xml' => 'http://xml-eu.amazon.com', //French xml server + ), + 'jp' => array( + 'ext' => 'jp' , //Japanese normal server, not co.jp! + 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server + 'xml' => 'http://xml.amazon.com' , //Japanese xml server + ), + 'uk' => array( + 'ext' => 'co.uk' , //UK normal server + 'nor' => 'http://www.amazon.co.uk' , //UK normal server + 'xml' => 'http://xml-eu.amazon.com', //UK xml server + ), + 'us' => array( + 'ext' => 'com' , //USA normal server + 'nor' => 'http://www.amazon.com' , //USA normal server + 'xml' => 'http://xml.amazon.com' , //USA xml server + ), +); + +include "aws_signed_request.php"; +$public_key ="AKIAJBXEHTNCU6LLFNIA"; +$private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA"; + +//for all parameters see if the user has overruled it or use the default +foreach ($Adefault as $i=>$d) { + $$i=isset($_GET[$i])?$_GET[$i]:$d; +} +//this is the data that is used to form the request for AWS +//this is the part that is search specific + + $parameters=array( + 'Operation' =>$operation , + //'Keywords' =>urlencode($search) , + 'SearchIndex' =>$searchindex , //Books for example. + "$searchparameter"=>stripslashes($searchparameterdata), + 'ItemPage' =>$page , //which page? + 'AssociateTag' =>$Aassociates_id[$locale], + 'MerchantId' =>'All', + 'Availability' =>'Available', + 'Condition' =>'All', + 'ResponseGroup' =>'Images,ItemAttributes' , //Small, Medium, Large or SellerListing + ); + +$ext=$Aserver[$locale]['ext']; +$file_data=$ext; +ksort($parameters); +foreach ($parameters as $i=>$d) { + $file_data.='&'.$i.'='.$d; +} + +$url=aws_signed_request($ext,$parameters,$public_key,$private_key); +//echo $url; + + $crl = curl_init(); + $timeout = 5; + curl_setopt ($crl, CURLOPT_URL,$url); + curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); + curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); + $ret = curl_exec($crl); + curl_close($crl); + echo $ret;