diff php/read/similar.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 385ddd7c4b55 ae1459564f66
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php/read/similar.php	Thu Feb 16 22:29:02 2017 +0000
@@ -0,0 +1,161 @@
+<?php
+
+function dbConnect($go)
+{
+	if($go == 1)
+	{
+		return "../../private/db.php"; 
+	}
+	else
+	{
+		return "../../../private/db.php"; 
+	}
+}
+
+function addAmazonSimilarBooks($isbn1, $loc, $go)
+{
+include dbConnect($go);
+
+$queryLoc = "CALL getLocation('$loc')"; //"select locname from location where LocID = $loc";
+$res = mysqli_query($link, $queryLoc) or exit( mysqli_error( $link ));
+mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+include dbConnect($go);
+
+$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
+$locale=$rows['locname'];
+
+$Adefault=array(
+  'language'           =>'en',           //what language to render the page in
+  'locale'             =>$locale,           //which server's products? available: ca,de,fr,jp,uk,us
+  'page'               =>1,              
+  'operation'          =>'SimilarityLookup',   
+  'searchparameter'    =>'ItemId',       //what kind of search?
+  'searchparameterdata'=>$isbn1,  //what to search for?
+);
+
+
+$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;
+}
+
+  $parameters=array(
+    'Operation'       =>$operation              ,
+    //'Keywords'        =>urlencode($search)      ,
+    //'SearchIndex'     =>$searchindex            ,  //Books for example.
+    "$searchparameter"=>$searchparameterdata    ,
+    'ItemPage'        =>$page                   ,  //which page?
+    'AssociateTag'    =>$Aassociates_id[$locale],
+    'ResponseGroup'   =>'Small'          ,  //Small, Medium, Large or SellerListing, Similarities
+	'Availability'=>'Available',
+  );
+  
+$ext=$Aserver[$locale]['ext'];  
+
+$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_RETURNTRANSFER, 1);
+        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
+        $ret = curl_exec($crl);
+        curl_close($crl);
+        //echo $ret;
+		
+$xml = new SimpleXMLElement($ret);
+
+//$isbn1 = $xml->Items->Request->SimilarityLookupRequest->ItemId;
+//echo $isbn1;
+
+$result = "";
+for($i=0;$i<sizeof($xml->Items->Item);$i++){
+   foreach($xml->Items->Item[$i]->ASIN as $isbn2){
+    //  echo $isbn2;
+
+	$group = $xml->Items->Item[$i]->ItemAttributes->ProductGroup;
+
+	//foreach one of these, create a new request to check whether its a book.
+	//if it is then add it to the return (or add it to the database)
+	if($group == 'Book')
+	{			
+		$query1 = "CALL b_getLinkID('$isbn1', '$isbn2', $loc)"; // "select ScoreID from scoretable where BookID1 = '$isbn1' and BookID2 = '$isbn2' and LocID = $loc";
+		//echo $query1;
+		$data1 = mysqli_query($link, $query1) or exit( mysqli_error( $link ));
+		mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+		include dbConnect($go); 
+
+	if ( mysqli_num_rows( $data1 ) < 1 )
+		{
+			$queryL = "CALL b_addNewLink('$isbn1','$isbn2',0,$loc)";
+			//echo $queryL;
+			$results1 = mysqli_query($link, $queryL);
+			
+			$rows=mysqli_fetch_array($results1, MYSQLI_ASSOC);
+			$linkid=$rows['LinkID'];
+			
+			//reset connection
+			mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+			include dbConnect($go); 
+			
+			//$scoreQuery = "CALL b_insertTempScore('$isbn1','$isbn2',$loc,$linkid,0)";		
+			//echo $scoreQuery;
+			//$scoreFinal = mysqli_query($link, $scoreQuery);
+			$result .= "<type>0</type>";
+			$result .= "<isbn>" . $isbn2 . "</isbn>";
+			$result .= "<linkID>" . trim($linkid) . "</linkID>";
+		}		
+	} 	  
+   }
+}  
+
+return $result;
+}
+
+?>