/home/a/aquarion/sites/www.aquarionics.com/epistula/contrib/amazon.php
All my code (That is, anything not in the "Others" list on the right) is BSD licenced.
You can also view this page as text/plain or colour-coded source
#!/usr/bin/php
<?PHP
#header("Content-Type: text/plain");
if (ini_get("allow_url_fopen") == true){
$getImages = true;
} else {
$getImages = false;
}
$_EP = parse_ini_file("../epistula.ini", true);
require($_EP['codedir']."/include/library.php");
function amazonSearch($mostly, $echo = false){
require_once("../include/AmazonSearch.php");
/* Set Amazon associates tag */
$Tag = 'aquarionics';
/* Set Amazon developer token */
$Token = 'D3DEH2KGMUKH2Q';
$doing = $mostly[0];
$AS = new AmazonSearch($Token, $Tag, "uk");
$Results = $AS->DoPowerSearch($doing['search'], "lite", $doing['department']);
$return = array();
foreach($mostly as $doing){
if ($echo){
echo "Doing: ".$doing['search']."\n";
}
$item = array();
$locales = array(
array('uk', '£',"UK"),
array(false, '$',"US"),
#array("jp", '¥',"JP"),
#array("dk", '€',"DK")
);
foreach($locales as $locale){
if ($echo){echo $locale[2]."\n";}
$AS = new AmazonSearch($Token, $Tag, $locale[0]);
$Results = $AS->DoPowerSearch($doing['search'], "lite", $doing['department']);
foreach($Results as $result){
if (!$item['title'] && $result[ProductName]){
$item['title'] = stripslashes($result[ProductName]);
}
if (!$item['author'] && $result['Authors'][0]){
$item['author'] = stripslashes(implode(" / ",$result['Authors']));
}
if ($echo){echo "\t".$item['author'].": ".$item['title']." ";}
if (!$item['image']){
if ($getImages){
$img = getimagesize($result['ImageUrlMedium']);
if ($img[0]."x".$img[1] != "1x1"){
$item['image'] = "<img src=\"".$result['ImageUrlMedium']."\" width=\"".$img[0]."\" height=\"".$img[1]."\">\n";
}
} else {
$item['image'] = "<img src=\"".$result['ImageUrlMedium']."\">\n";
}
}
if (preg_match("#^not yet#i",$result[Availability])){
if ($echo){echo "(!Yet)";}
} elseif (preg_match("#out of stock#i",$result[Availability])){
if ($echo){echo "(OOS)";}
#echo "OOS";
} elseif (!$result[OurPrice]) {
if ($echo){echo "(!Price)";}
#echo "No Price";
} else {
if ($echo){echo "(".$result[OurPrice].")";}
$price = preg_replace("#^\D+#","",$result[OurPrice]);
if ($price < $item['price'][$locale[1]] || !$item['price'][$locale[1]]){
$item['price'][$locale[1]] = $price;
$item['url'][$locale[1]] = $result[Url];
}
}
if ($echo){echo "\n";}
}
#print_r($Results);
}
if ($doing['review']){
$return['review'] = $doing['review'];
}
$return[] = $item;
if ($echo){echo "Done\n";}
}
if ($echo){print_r($return);}
return $return;
}
$mostly = array(
'Recently' => array(
array('department' => "books", 'search' => "author:'Matthew Baylis' title:'The Last Ealing Comedy'"),
array('department' => "books", 'search' => "author:'Raymond Feist' title:'King of Foxes'"),
array('department' => "books", 'search' => "author:'Matt Beaumont' title:'E'"),
array('department' => "books", 'search' => "title:'Thraxas at the Races'"),
array('department' => "books", 'search' => "author:'Lynne Truss' title:'Eats, Shoots & Leaves'"),
array('department' => "books", 'search' => "author:' Jon Courtenay Grimwood' title:'Pashazade'"),
),
'Upcoming' => array(
#array('department' => "books", 'search' => "author:'' title:''"),
array('department' => "books", 'search' => "author:'Eric Garcia' title:'Casual Rex'"),
array('department' => "books", 'search' => "author:'Timothy Collings' title:'The Pirahna Club'"),
array('department' => "books", 'search' => "author:'Neal Stephenson' title:'Quicksilver'"),
#array('department' => "books", 'search' => "author:'Sarah Emily Miano' title:'Encyclopaedia of Snow'"),
array('department' => "books", 'search' => "author:'John Marco' title:'The Jackal of Nar'"),
array('department' => "books", 'search' => "author:'John Marco' title:'The Grand Design'"),
#array('department' => "books", 'search' => "author:'Michael de Larrabeiti' title:'The Borribles'"),
array('department' => "books", 'search' => "author:'James Bamford' title:'Body of Secrets'"),
array('department' => "books", 'search' => "author:'Robert Littell' title:'The Company'"),
array('department' => "books", 'search' => "title:'Hounds of the Morrigan'")
)
);
foreach ($mostly as $index => $list){
$array[$index] = amazonSearch($list);
}
$fp = fopen($_EP['datadir']."/reading.dat","wb");
fwrite($fp,serialize($array));
fclose($fp);
?>
Using a heavily customised version of Tom's PHPCode2ValidXHTML Thing