# HG changeset patch
# User Charlie Root
# Date 1546729210 18000
# Node ID dbc006408d2b450347ee7a5be46117f8d7560167
# Parent 3f400072bf14de91479134450bcf0d2beacc9c77
ASSUMES we have SetEnv PHP_VALUE "include_path =.:/var/test/private:/var/test/ywww:/usr/share/php" in apache2/.../test.conf
use dl(...) for debug logging, defined in dlog.php
use doAmazonRequest in amazonBookSearch
use ../private/web.php (q.v., not in mercurial) for Aserver and Aassociates
Started by updating from 40:c24ae74bf6d5, i.e. just before the bug on the main line
diff -r 3f400072bf14 -r dbc006408d2b dlog.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dlog.php Sat Jan 05 18:00:10 2019 -0500
@@ -0,0 +1,12 @@
+
diff -r 3f400072bf14 -r dbc006408d2b php/read/aws_signed_request.php
--- a/php/read/aws_signed_request.php Sat Jan 05 06:21:12 2019 -0500
+++ b/php/read/aws_signed_request.php Sat Jan 05 18:00:10 2019 -0500
@@ -3,49 +3,6 @@
//20090627/Jaap van Ganswijk: This is a modified version, see the
//return statement some lines before the end of the last function.
-
-$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
- ),
- );
-
-
if (!function_exists("aws_signed_request")) {
function aws_signed_request($region, $params, $public_key, $private_key)
{
diff -r 3f400072bf14 -r dbc006408d2b php/read/getBookDetails.php
--- a/php/read/getBookDetails.php Sat Jan 05 06:21:12 2019 -0500
+++ b/php/read/getBookDetails.php Sat Jan 05 18:00:10 2019 -0500
@@ -1,5 +1,7 @@
Name == "Subjects")
@@ -23,7 +25,7 @@
}
}
-global $out,$isbn;
+global $out,$isbn,$Aserver,$Aassociates_id;
if(isset($_GET['isbn'])){
$isbn = $_GET['isbn'];
if(isset($_GET['locale'])){
@@ -106,9 +108,7 @@
{
include "aws_signed_request.php";
include_once "../../xml/doAmazonRequest.inc";
- file_put_contents('/var/ywww/debug/phpDebug',
- "nbd proceeding: $isbn\n",
- FILE_APPEND);
+ dl("nbd proceeding: $isbn\n");
//book does not exist already so look up all the info from browse nodes....
@@ -128,46 +128,6 @@
);
//change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
- $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
- ),
- );
//for all parameters see if the user has overruled it or use the default
foreach ($Adefault as $i=>$d) {
@@ -192,14 +152,10 @@
//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);
+ dl("Caught one bd: $isbn\n");
+ dl(print_r($out, TRUE)."\n");
} );
- include "../../../private/db.php";
+ include "db.php";
$title="";
$author="";
@@ -317,9 +273,7 @@
if (!$res) {
$err=mysqli_error( $link );
mysqli_close($link);
- file_put_contents('/var/ywww/debug/phpDebug',
- "anb failed: $err, $pubDate, $g2, $publisher, $title\n",
- FILE_APPEND);
+ dl("anb failed: $err, $pubDate, $g2, $publisher, $title\n");
exit($err);
}
mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
@@ -340,9 +294,7 @@
$output .= "
Thank you for using YourNextRead
-
+
";
if($iPhone && !$iPad)
{
@@ -111,7 +112,7 @@
for($i=0;$i Thank you for using YourNextRead
-
+
";
if($iPhone && !$iPad)
{
@@ -291,10 +283,10 @@
echo $linkedRecommended . " " . $vote . " Thank you for using YourNextRead
-
+
";
if($iPhone && !$iPad)
{
diff -r 3f400072bf14 -r dbc006408d2b xml/amazonBookSearch.php
--- a/xml/amazonBookSearch.php Sat Jan 05 06:21:12 2019 -0500
+++ b/xml/amazonBookSearch.php Sat Jan 05 18:00:10 2019 -0500
@@ -1,5 +1,9 @@
'en', //what language to render the page in
'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us
@@ -12,51 +16,6 @@
'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 ="AKIAIHTNWC7L6LOUY4LQ";
-$private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde";
-
//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;
@@ -77,39 +36,17 @@
'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;
+
+try {
+ $ret=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'s',False);
}
-
-$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);
- $gotit=0;
- $semaphore = new SyncSemaphore("Amazon");
- $gotit = $semaphore->lock(1000);
- if (!$gotit) {
- file_put_contents('/var/ywww/debug/phpDebug',
- "Got it: ".(int)$gotit." 3\n",FILE_APPEND);
- $gotit=$semaphore->lock(1000);
- file_put_contents('/var/ywww/debug/phpDebug',
- "Got it: ".(int)$gotit." 3a\n",FILE_APPEND);
- }
- $ret = curl_exec($crl);
- curl_close($crl);
- usleep(500000);
- if ($gotit) {
- $semaphore->unlock();
- }
- else {
- file_put_contents('/var/ywww/debug/phpDebug',"W/o lock 3b\n",FILE_APPEND);
- }
- echo $ret;
+catch (Exception $e) {
+ if ($e->getMessage()=='AWS.ECommerceService.NoExactMatches') {
+ // Seems to be an 'OK' thing...
+ $ret=''.$code.'
~s';
- $setBoundary = preg_replace($remove1,'', $setBoundary);
- $remove2 = '~
~s';
- $setBoundary = preg_replace($remove2,'', $setBoundary);
- $remove3 = '~~s';
- $setBoundary = preg_replace($remove3,'', $setBoundary);
- $setBoundary2 = str_replace(' ','BOTTOM', $setBoundary2);
- //replace with BOTTOM
-
- if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
- {
- $reviewContents = $reviews[1];
- //print_r($reviewContents);
- $review1 = trim($reviewContents[0]);
- $review1 = str_replace("\n", "", $review1);
- $review1 = str_replace("\r", "", $review1);
- if (isset($reviewContents[1])) {
- $review2 = trim($reviewContents[1]);
- $review2 = str_replace("\n", "", $review2);
- $review2 = str_replace("\r", "", $review2);
- }
- else {
- $review2 = "";
- }
- if (isset($reviewContents[2])) {
- $review3 = trim($reviewContents[2]);
- $review3 = str_replace("\n", "", $review3);
- $review3 = str_replace("\r", "", $review3);
- }
- else {
- $review3 = "";
- }
- }
- else
- {
- $review1 = "";
- $review2 = "";
- $review3 = "";
- //echo "EPIC FAIL";
- }
-
- unset($xml->Items->Item->CustomerReviews);
- $xdoc = new DomDocument;
- $xdoc->loadXML($xml->asXML());
-
- $cReviews = $xdoc ->createElement('CustomerReviews');
- $cReviewHolder = $xdoc ->createElement('Review');
- $cReview = $xdoc ->createElement('Content');
- $cReviewHolder2 = $xdoc ->createElement('Review');
- $cReview2 = $xdoc ->createElement('Content');
- $cReviewHolder3 = $xdoc ->createElement('Review');
- $cReview3 = $xdoc ->createElement('Content');
-
- $txtNode = $xdoc ->createTextNode ($review1);
- $cReview -> appendChild($txtNode);
-
- $txtNode2 = $xdoc ->createTextNode ($review2);
- $cReview2 -> appendChild($txtNode2);
-
- $txtNode3 = $xdoc ->createTextNode ($review3);
- $cReview3 -> appendChild($txtNode3);
-
- $cReviewHolder -> appendChild($cReview);
- $cReviewHolder2 -> appendChild($cReview2);
- $cReviewHolder3 -> appendChild($cReview3);
-
- $cReviews -> appendChild($cReviewHolder);
- $cReviews -> appendChild($cReviewHolder2);
- $cReviews -> appendChild($cReviewHolder3);
-
- $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
- $newXML = simplexml_import_dom($xdoc);
- $output = $newXML->asXml();
- }
-
- if($go == 1) {
- $item = $xml->Items->Item[0];
- if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
- $title = $item->ItemAttributes->Title; }
- else { $title = "[no title]"; };
- file_put_contents('/var/ywww/debug/phpDebug',"win: $title\n",
- FILE_APPEND);
- return $output;
- }
- else {
- if ($xml->Items->Item) {
- $title = $xml->Items->Item[0]->ItemAttributes->Title;
- $author = $xml->Items->Item[0]->ItemAttributes->Author;
- $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
- $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
- if($dewey == "")
- $dewey = "null";
- $imageURL = $xml->Items->Item[0]->MediumImage->URL;
- $salesRank = $xml->Items->Item[0]->SalesRank;
- $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
- if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
- if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
- if (strlen($pubDate)==0) {
- $pubDate="null";
- }
- else {
- $pubDate="\"$pubDate\"";
- }
- $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
- }
- else {
- $title = $salesRank = "";
- $dewey = "null";
- }
-
- $genreID = "";
- $genre = "";
- $genArr = array();
-
- if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
- for($i=0;$i
','', $setBoundary);
- //remove all extra crap;
- $setBoundary3 = str_replace('AccountLimitExceeded
~s';
+ $setBoundary = preg_replace($remove1,'', $setBoundary);
+ $remove2 = '~
~s';
+ $setBoundary = preg_replace($remove2,'', $setBoundary);
+ $remove3 = '~~s';
+ $setBoundary = preg_replace($remove3,'', $setBoundary);
+ $setBoundary2 = str_replace(' ','BOTTOM', $setBoundary2);
+ //replace with BOTTOM
+
+ if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
+ {
+ $reviewContents = $reviews[1];
+ //print_r($reviewContents);
+ $review1 = trim($reviewContents[0]);
+ $review1 = str_replace("\n", "", $review1);
+ $review1 = str_replace("\r", "", $review1);
+ if (isset($reviewContents[1])) {
+ $review2 = trim($reviewContents[1]);
+ $review2 = str_replace("\n", "", $review2);
+ $review2 = str_replace("\r", "", $review2);
+ }
+ else {
+ $review2 = "";
+ }
+ if (isset($reviewContents[2])) {
+ $review3 = trim($reviewContents[2]);
+ $review3 = str_replace("\n", "", $review3);
+ $review3 = str_replace("\r", "", $review3);
+ }
+ else {
+ $review3 = "";
+ }
+ }
+ else
+ {
+ $review1 = "";
+ $review2 = "";
+ $review3 = "";
+ //echo "EPIC FAIL";
+ }
+
+ unset($xml->Items->Item->CustomerReviews);
+ $xdoc = new DomDocument;
+ $xdoc->loadXML($xml->asXML());
+
+ $cReviews = $xdoc ->createElement('CustomerReviews');
+ $cReviewHolder = $xdoc ->createElement('Review');
+ $cReview = $xdoc ->createElement('Content');
+ $cReviewHolder2 = $xdoc ->createElement('Review');
+ $cReview2 = $xdoc ->createElement('Content');
+ $cReviewHolder3 = $xdoc ->createElement('Review');
+ $cReview3 = $xdoc ->createElement('Content');
+
+ $txtNode = $xdoc ->createTextNode ($review1);
+ $cReview -> appendChild($txtNode);
+
+ $txtNode2 = $xdoc ->createTextNode ($review2);
+ $cReview2 -> appendChild($txtNode2);
+
+ $txtNode3 = $xdoc ->createTextNode ($review3);
+ $cReview3 -> appendChild($txtNode3);
+
+ $cReviewHolder -> appendChild($cReview);
+ $cReviewHolder2 -> appendChild($cReview2);
+ $cReviewHolder3 -> appendChild($cReview3);
+
+ $cReviews -> appendChild($cReviewHolder);
+ $cReviews -> appendChild($cReviewHolder2);
+ $cReviews -> appendChild($cReviewHolder3);
+
+ $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
+ $newXML = simplexml_import_dom($xdoc);
+ $output = $newXML->asXml();
+ }
+
+ if($go == 1) {
+ $item = $xml->Items->Item[0];
+ if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
+ $title = $item->ItemAttributes->Title; }
+ else { $title = "[no title]"; };
+ dl("win: $title\n");
+ return $output;
+ }
+ else {
+ if ($xml->Items->Item) {
+ $title = $xml->Items->Item[0]->ItemAttributes->Title;
+ $author = $xml->Items->Item[0]->ItemAttributes->Author;
+ $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
+ $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
+ if($dewey == "")
+ $dewey = "null";
+ $imageURL = $xml->Items->Item[0]->MediumImage->URL;
+ $salesRank = $xml->Items->Item[0]->SalesRank;
+ $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
+ if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
+ if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
+ if (strlen($pubDate)==0) {
+ $pubDate="null";
+ }
+ else {
+ $pubDate="\"$pubDate\"";
+ }
+ $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
+ }
+ else {
+ $title = $salesRank = "";
+ $dewey = "null";
+ }
+
+ $genreID = "";
+ $genre = "";
+ $genArr = array();
+
+ if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
+ for($i=0;$i
','', $setBoundary);
+ //remove all extra crap;
+ $setBoundary3 = str_replace('AccountLimitExceeded