Aquarionics

/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', '&pound;',"UK"), 
            array(false, '$',"US"), 
            #array("jp", '&yen;',"JP"), 
            #array("dk", '&euro;',"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

Nicholas 'Aquarion' Avenell is a web developer in London, you can find out more about him or how to get in touch.

There are more Articles, Projects, Journal Entries, Photographs and things that defy description here, too.

If you're looking for something specific, there are Calendar & Category -based lists of everything.

And if you want to follow stuff that appears here, try a Syndication Feed, or the generic Feed of everything.


Aquarion's last Twitter was: [updating]
Twitter last updated


© 2000 to 2008 inclusive Nicholas Avenell
All comments are the property of their creators, published with permission
(Unless otherwise indicated, the opinions and sentiments expressed on this site are those of the author and not of any organisation of which he is an affiliate, including his employer. Caveat Lector, E&OE. sigh)
0.224 seconds, 1 queries, 2.68Mb on Fri, 04 Jul 2008 18:46:09 +0000, Not cached
Generated by Epistula Version 2.0.3