changeset 13:b78209a5fba1

Merge
author Rob Boland <robert@metail.co.uk>
date Sat, 18 Feb 2017 15:18:47 +0000
parents 970a4834afff (current diff) c9ebf871114b (diff)
children 1477b5e6dd16 093e42d5a874 77ff181476b8
files
diffstat 3 files changed, 143 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/php/read/getBookDetails.php	Fri Feb 17 15:24:17 2017 +0000
+++ b/php/read/getBookDetails.php	Sat Feb 18 15:18:47 2017 +0000
@@ -189,9 +189,6 @@
 		  }
 
 
- file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ".
-		   print_r($parameters,TRUE)."\n",FILE_APPEND);
-
 		$ext=$Aserver[$locale]['ext'];  
 		$file_data=$ext;
 		ksort($parameters);
@@ -213,131 +210,141 @@
 
 		//echo $out;
 		
-	if (preg_match("<Error>",$out)) {
-	  $xml = new SimpleXMLElement($out);	
-	  $resName=$xml->getName();
-	  $code=$xml->Error->Code;
-	  file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, ".
-			    $xml->Error->Code."\n",FILE_APPEND);
-	}
-	else {
-		$xml = new SimpleXMLElement($out);
-		//use this xml to pull out the necessary information and save it
-	set_error_handler(function () {
-	    global $out,$isbn;
-	    file_put_contents('/var/ywww/debug/phpDebug',
-			      "Caught one bd: ".$isbn,
-			      FILE_APPEND);
-	    file_put_contents('/var/ywww/debug/phpDebug',
-			      print_r($out, TRUE)."\n",
-			      FILE_APPEND);
-			      } );
+		if (preg_match("<Error>",$out)) {
+		  $xml = new SimpleXMLElement($out);	
+		  $resName=$xml->getName();
+		  $code=$xml->Error->Code;
+		  file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND);
+		  if ($code=='RequestThrottled') {
+		    usleep(200000); // Try to reduce throttling until we get a 
+		    // principled solution in place
+		  }
+		  else {
+		    file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ".
+				      print_r($parameters,TRUE)."\n",FILE_APPEND);
+		    if ($code=="") {
+		      file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$out\n",FILE_APPEND);
+		    }
+		  }
+		}
+		else {
+		  $xml = new SimpleXMLElement($out);
+		  //use this xml to pull out the necessary information and save it
+		  set_error_handler(function () {
+		      global $out,$isbn;
+		      file_put_contents('/var/ywww/debug/phpDebug',
+					"Caught one bd: ".$isbn,
+					FILE_APPEND);
+		      file_put_contents('/var/ywww/debug/phpDebug',
+					print_r($out, TRUE)."\n",
+					FILE_APPEND);
+		    } );
 	
-		$title="";
-		$author="";
-		$binding="";
-		$dewey="";
-		$imageURL="";
-		$salesRank="";
-		$pubDate="";
-		$publisher="";
+		  $title="";
+		  $author="";
+		  $binding="";
+		  $dewey="";
+		  $imageURL="";
+		  $salesRank="";
+		  $pubDate="";
+		  $publisher="";
 	
-		$title = $xml->Items->Item->ItemAttributes->Title;
-		$author = $xml->Items->Item->ItemAttributes->Author;
-		$binding = $xml->Items->Item->ItemAttributes->Binding;
-		$dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
-		if($dewey == "")
-			$dewey = "null";
-		$imageURL = $xml->Items->Item->MediumImage->URL;
-		$salesRank = $xml->Items->Item->SalesRank;
-		$pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
-		$publisher = $xml->Items->Item->ItemAttributes->Publisher;
-		restore_error_handler();
-		/*echo $title;
-		echo $author;
-		echo $binding;
-		echo $dewey;
-		echo $imageURL;
-		echo $salesRank;
-		echo $pubDate;
-		echo $publisher;*/
+		  $title = $xml->Items->Item->ItemAttributes->Title;
+		  $author = $xml->Items->Item->ItemAttributes->Author;
+		  $binding = $xml->Items->Item->ItemAttributes->Binding;
+		  $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
+		  if($dewey == "")
+		    $dewey = "null";
+		  $imageURL = $xml->Items->Item->MediumImage->URL;
+		  $salesRank = $xml->Items->Item->SalesRank;
+		  $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
+		  $publisher = $xml->Items->Item->ItemAttributes->Publisher;
+		  restore_error_handler();
+		  /*echo $title;
+		   echo $author;
+		   echo $binding;
+		   echo $dewey;
+		   echo $imageURL;
+		   echo $salesRank;
+		   echo $pubDate;
+		   echo $publisher;*/
 		
-		$genreID = "";
-		$genre = "";		
-		$genArr = array();
-		$g1 = "null";
-                $g2 = "null";
-                $g3 = "null";
-		if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){		
-		for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){					
-			//sexy recursive function
-			findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
+		  $genreID = "";
+		  $genre = "";		
+		  $genArr = array();
+		  $g1 = "null";
+		  $g2 = "null";
+		  $g3 = "null";
+		  if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){		
+		    for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){					
+		      //sexy recursive function
+		      findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
 			
-			if($genre != "")
-				$genArr[strval($genreID)] = strval($genre);
-				//$genArr[$i] = array(strval($genreID) => strval($genre));
+		      if($genre != "")
+			$genArr[strval($genreID)] = strval($genre);
+		      //$genArr[$i] = array(strval($genreID) => strval($genre));
 
-			//echo $genre;
-			//echo $genreID;
+		      //echo $genre;
+		      //echo $genreID;
 			
-			$genre = "";
-			$genreID = "";
-		}
+		      $genre = "";
+		      $genreID = "";
+		    }
 		
-		$g1 = "null";
-		$g2 = "null";
-		$g3 = "null";
-		$loop = 1;
+		    $g1 = "null";
+		    $g2 = "null";
+		    $g3 = "null";
+		    $loop = 1;
 		
-		foreach ($genArr as $key => $value) {
-			//echo "$key => $value";
-			$queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
-			//echo $queryG;
-			$resG = mysqli_query($link, $queryG);
+		    foreach ($genArr as $key => $value) {
+		      //echo "$key => $value";
+		      $queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
+		      //echo $queryG;
+		      $resG = mysqli_query($link, $queryG);
 			
-			switch ($loop) {
-			case 1:
-				$g1 = $key;
-				break;
-			case 2:
-				$g2 = $key;
-				break;
-			case 3:
-				$g3 = $key;
-				break;
-			}
+		      switch ($loop) {
+		      case 1:
+			$g1 = $key;
+			break;
+		      case 2:
+			$g2 = $key;
+			break;
+		      case 3:
+			$g3 = $key;
+			break;
+		      }
 			
-			$loop++;
-		}
-		}
+		      $loop++;
+		    }
+		  }
 		
-		if($salesRank == "")
-			$salesRank = "null";
+		  if($salesRank == "")
+		    $salesRank = "null";
 		
-		mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
-		include "../../../private/db.php";
+		  mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+		  include "../../../private/db.php";
 		
-		$title = strtr($title, '"', "'");	
-		$queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";	
-		//echo $queryInsert;
+		  $title = strtr($title, '"', "'");	
+		  $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";	
+		  //echo $queryInsert;
 		
-		$resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
-		mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
+		  $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
+		  mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
 
 		
-		$output .=  "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
-		$output .=  "<Title>" . htmlspecialchars($title) . "</Title>";
-		$output .=  "<Author>" . htmlspecialchars($author) . "</Author>";
-		$output .=  "<Binding>" . htmlspecialchars($binding) . "</Binding>";
-		$output .=  "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
-		$output .=  "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
-		$output .=  "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
-		$output .=  "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
-		$output .=  "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
-		$output .=  "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
-		$output .=  "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
-		$output .=  "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";	
-		$output .=  "<ProductGroup>Book</ProductGroup>";
+		  $output .=  "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
+		  $output .=  "<Title>" . htmlspecialchars($title) . "</Title>";
+		  $output .=  "<Author>" . htmlspecialchars($author) . "</Author>";
+		  $output .=  "<Binding>" . htmlspecialchars($binding) . "</Binding>";
+		  $output .=  "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
+		  $output .=  "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
+		  $output .=  "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
+		  $output .=  "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
+		  $output .=  "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
+		  $output .=  "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
+		  $output .=  "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
+		  $output .=  "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";	
+		  $output .=  "<ProductGroup>Book</ProductGroup>";
 		}
 	}
 	
--- a/us/index.php	Fri Feb 17 15:24:17 2017 +0000
+++ b/us/index.php	Sat Feb 18 15:18:47 2017 +0000
@@ -140,8 +140,22 @@
 				{
 					$bookDetails = getAmazonDet($isbn,1,'us'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					// HST added this
+					if (preg_match("<Error>",$bookDetails)) {
+					  $resName=$bookXML->getName();
+					  $code=$bookXML->Error->Code;
+					  file_put_contents('/var/ywww/debug/phpDebug',"Losing 3: $resName, ".
+							    $code."\n",FILE_APPEND);
+					  if ($code=='RequestThrottled') {
+					    usleep(200000); // Try to reduce throttling until we get a 
+					    // principled solution in place
+					  }
+					  $title = "";
+					}
+					else {
+					  $title = $bookXML->Items->Item[0]->ItemAttributes->Title;
+					  $author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
--- a/xml/getAmazonInfo.php	Fri Feb 17 15:24:17 2017 +0000
+++ b/xml/getAmazonInfo.php	Sat Feb 18 15:18:47 2017 +0000
@@ -94,8 +94,6 @@
 
 $url=aws_signed_request($ext,$parameters,$public_key,$private_key);  
 //echo $url;
- file_put_contents('/var/ywww/debug/phpDebug',"parms: $go".
-		   print_r($parameters,TRUE)."\n",FILE_APPEND);
         $crl = curl_init();
         $timeout = 5;
         curl_setopt ($crl, CURLOPT_URL,$url);
@@ -117,12 +115,18 @@
 	  $xml = new SimpleXMLElement($output);	
 	  $resName=$xml->getName();
 	  $code=$xml->Error->Code;
-	  file_put_contents('/var/ywww/debug/phpDebug',"Losing: $resName, ".
-			    $code."\n",FILE_APPEND);
+	  file_put_contents('/var/ywww/debug/phpDebug',"Losing: $resName, $code\n",FILE_APPEND);
 	  if ($code=='RequestThrottled') {
 	    usleep(200000); // Try to reduce throttling until we get a 
 	    // principled solution in place
 	  }
+	  else {
+	     file_put_contents('/var/ywww/debug/phpDebug',"parms: $go\n".
+		   print_r($parameters,TRUE)."\n",FILE_APPEND);
+	     if ($code=="") {
+	       file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND);
+	     }
+	  }
 	}
 	else {
 	  $xml = new SimpleXMLElement($output);