Mercurial > hg > ywww
annotate xml/getAmazonInfo.php @ 32:8130865e9e82
refactor to try to improve error handling
| author | Charlie Root |
|---|---|
| date | Fri, 04 Jan 2019 09:50:55 -0500 |
| parents | 4124f103b46b |
| children | c9d9b76ecbf9 |
| rev | line source |
|---|---|
| 4 | 1 <?php |
| 2 | |
| 3 function getAmazonDet($isbn,$go,$localeIn) | |
| 4 { | |
| 32 | 5 $Adefault=array( |
| 6 'language' =>'en', //what language to render the page in | |
| 7 'locale' =>$localeIn, //which server's products? available: ca,de,fr,jp,uk,us | |
| 8 //'mode' =>'books', //what product category? | |
| 9 'page' =>1, //first page to show (we are counting from 1 not 0) | |
| 10 //'search' =>'Machiavelli', //what to search for? | |
| 11 'operation' =>'ItemLookup', //what to do? //ItemSearch | |
| 12 // 'searchindex' =>'Books', //what product category for search? | |
| 13 'searchparameter' =>'ItemId', //what kind of search? | |
| 14 'searchparameterdata'=>$isbn, //what to search for? | |
| 15 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' | |
| 16 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending | |
| 17 'show_url' =>false, //debug: show XML request url to be send to Amazon? | |
| 18 'show_xml' =>false, //debug: show incoming XML code from Amazon? | |
| 19 ); | |
| 20 //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 | |
| 21 //for all parameters see if the user has overruled it or use the default | |
| 22 foreach ($Adefault as $i=>$d) { | |
| 23 $$i=isset($_GET[$i])?$_GET[$i]:$d; | |
| 24 } | |
| 25 switch($locale){ | |
| 26 case "us": | |
| 27 $loc = 0; | |
| 28 break; | |
| 29 case "uk": | |
| 30 $loc = 1; | |
| 31 break; | |
| 32 case "ca": | |
| 33 $loc = 2; | |
| 34 break; | |
| 35 case "de": | |
| 36 $loc = 3; | |
| 37 break; | |
| 38 case "fr": | |
| 39 $loc = 4; | |
| 40 break; | |
| 41 }; | |
| 42 | |
| 43 for ($i=1; $i<=3; $i++) { | |
| 44 try { | |
| 45 return getAmazonDetRemote($go,$language,$locale,$loc, | |
| 46 $page,$operation,$searchparameter, | |
| 47 $searchparameterdata, | |
| 48 $show_array,$show_url,$show_xml); | |
| 49 } | |
| 50 catch (Exception $code) { | |
| 51 file_put_contents('/var/ywww/debug/phpDebug', | |
| 52 "Bang: $code $i\n",FILE_APPEND); | |
| 53 if ($code=='RequestThrottled') { | |
| 54 usleep(200000); // Try to reduce throttling until we get a | |
| 55 // principled solution in place | |
| 56 $bail=False; | |
| 57 } | |
| 58 else { | |
| 59 $bail=True; | |
| 60 } | |
| 61 } | |
| 62 if ($bail) { break; } | |
| 63 } | |
| 64 return getAmazonDetLocal($go,$language,$loc, | |
| 65 $page,$operation,$searchparameter, | |
| 66 $searchparameterdata, | |
| 67 $show_array,$show_url,$show_xml); | |
| 68 } | |
| 69 | |
| 70 function getAmazonDetRemote($go,$language,$locale,$loc, | |
| 71 $page,$operation,$searchparameter, | |
| 72 $searchparameterdata, | |
| 73 $show_array,$show_url,$show_xml) | |
| 74 { | |
| 4 | 75 global $output; |
| 76 | |
| 32 | 77 $Aassociates_id=array( |
| 78 'uk' => 'bookwhack-21', | |
| 79 'us' => 'your02b-20', | |
| 80 'ca' => 'book009-20', | |
| 81 'de' => 'book04c-21', | |
| 82 'fr' => 'book07f-21', | |
| 83 ); | |
| 4 | 84 |
| 32 | 85 $Aserver=array( |
| 86 'ca' => array( | |
| 87 'ext' => 'ca' , //Canadian normal server | |
| 88 'nor' => 'http://www.amazon.ca' , //Canadian normal server | |
| 89 'xml' => 'http://xml.amazon.com' , //Canadian xml server | |
| 90 ), | |
| 91 'de' => array( | |
| 92 'ext' => 'de' , //German normal server | |
| 93 'nor' => 'http://www.amazon.de' , //German normal server | |
| 94 'xml' => 'http://xml-eu.amazon.com', //German xml server | |
| 95 ), | |
| 96 'fr' => array( | |
| 97 'ext' => 'fr' , //French normal server | |
| 98 'nor' => 'http://www.amazon.fr' , //French normal server | |
| 99 'xml' => 'http://xml-eu.amazon.com', //French xml server | |
| 100 ), | |
| 101 'jp' => array( | |
| 102 'ext' => 'jp' , //Japanese normal server, not co.jp! | |
| 103 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server | |
| 104 'xml' => 'http://xml.amazon.com' , //Japanese xml server | |
| 105 ), | |
| 106 'uk' => array( | |
| 107 'ext' => 'co.uk' , //UK normal server | |
| 108 'nor' => 'http://www.amazon.co.uk' , //UK normal server | |
| 109 'xml' => 'http://xml-eu.amazon.com', //UK xml server | |
| 110 ), | |
| 111 'us' => array( | |
| 112 'ext' => 'com' , //USA normal server | |
| 113 'nor' => 'http://www.amazon.com' , //USA normal server | |
| 114 'xml' => 'http://xml.amazon.com' , //USA xml server | |
| 115 ), | |
| 116 ); | |
| 4 | 117 |
| 32 | 118 //if(go != 1) |
| 119 //include "aws_signed_request.php"; | |
| 120 $public_key ="AKIAIHTNWC7L6LOUY4LQ"; | |
| 121 $private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde"; | |
| 122 //this is the data that is used to form the request for AWS | |
| 123 //this is the part that is search specific | |
| 4 | 124 $parameters=array( |
| 32 | 125 'Operation' =>$operation , |
| 126 //'Keywords' =>urlencode($search) , | |
| 127 //'SearchIndex' =>$searchindex , //Books for example. | |
| 128 "$searchparameter"=>$searchparameterdata , | |
| 129 'ItemPage' =>$page , //which page? | |
| 130 'AssociateTag' =>$Aassociates_id[$locale], | |
| 131 'ResponseGroup' =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes' , //Small, Medium, Large or SellerListing,'BrowseNodes',// , | |
| 132 'ReviewSort' =>'-HelpfulVotes' | |
| 133 ); | |
| 4 | 134 |
| 32 | 135 $requestURI = $_SERVER['REQUEST_URI']; |
| 136 $requestIP = $_SERVER['REMOTE_ADDR']; | |
| 137 // if ($requestIP=="173.161.113.65" || $requestIP=="141.8.132.25") { | |
| 138 // $delay=60; | |
| 139 // file_put_contents('/var/ywww/debug/phpDebug', | |
| 140 // "bad guy: $requestIP, $requestURI\n", | |
| 141 // FILE_APPEND); | |
| 142 // sleep($delay); | |
| 143 // # No, can't do this | |
| 144 // # return; # bomb! | |
| 145 // # 'Kung', sitting on my desk in the office while I'm at home, | |
| 146 // # is occasionally hitting xml/getAmazonInfo.php: | |
| 147 // # e.g. Losing: ItemLookupErrorResponse, RequestThrottled, 129.215.197.36, /xml/getAmazonInfo.php?searchparameterdata=075154454X&locale=uk | |
| 148 // # repeatedly, same params | |
| 149 // } | |
| 150 $ext=$Aserver[$locale]['ext']; | |
| 151 $file_data=$ext; | |
| 152 ksort($parameters); | |
| 153 foreach ($parameters as $i=>$d) { | |
| 154 $file_data.='&'.$i.'='.$d; | |
| 155 } | |
| 156 $gotit=0; | |
| 157 $url=aws_signed_request($ext,$parameters,$public_key,$private_key); | |
| 158 $crl = curl_init(); | |
| 159 $timeout = 5; | |
| 160 curl_setopt ($crl, CURLOPT_URL,$url); | |
| 161 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
| 162 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
| 163 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
| 164 $semaphore = new SyncSemaphore("Amazon"); | |
| 165 $gotit = $semaphore->lock(1000); | |
| 166 if (!$gotit) { | |
| 167 file_put_contents('/var/ywww/debug/phpDebug', | |
| 168 "Got it: ".(int)$gotit." $requestIP 1\n",FILE_APPEND); | |
| 169 $gotit=$semaphore->lock(1000); | |
| 170 file_put_contents('/var/ywww/debug/phpDebug', | |
| 171 "Got it: ".(int)$gotit." $requestIP 1a\n",FILE_APPEND); | |
| 172 } | |
| 173 $output = curl_exec($crl); | |
| 174 curl_close($crl); | |
| 175 usleep(500000); | |
| 176 if ($gotit) { | |
| 177 $semaphore->unlock(); | |
| 178 } | |
| 179 else { | |
| 180 file_put_contents('/var/ywww/debug/phpDebug', | |
| 181 "W/o lock for $requestIP 1b\n",FILE_APPEND); | |
| 182 } | |
| 183 $review = ""; | |
| 184 $review1 = ""; | |
| 185 $review2 = ""; | |
| 186 $review3 = ""; | |
| 187 // HST added this | |
| 188 $mm=array(); | |
| 189 if (preg_match("/<Error>/",$output,$mm)) { | |
| 190 $xml = new SimpleXMLElement($output); | |
| 191 $resName=$xml->getName(); | |
| 192 $code=$xml->Error->Code; | |
| 193 if (!$code) { | |
| 194 $code=$xml->Items->Request->Errors->Error->Code; | |
| 195 } | |
| 196 file_put_contents('/var/ywww/debug/phpDebug',"Losing: ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND); | |
| 197 if ($code!='RequestThrottled') { | |
| 198 file_put_contents('/var/ywww/debug/phpDebug',"parms: $go\nurl: $url\n". | |
| 199 print_r($parameters,TRUE)."\n",FILE_APPEND); | |
| 200 if ($code=="") { | |
| 201 file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND); | |
| 202 } | |
| 203 } | |
| 204 throw new Exception($code); | |
| 205 } | |
| 206 else { | |
| 207 $xml = new SimpleXMLElement($output); | |
| 208 set_error_handler(function () { | |
| 209 global $output; | |
| 210 file_put_contents('/var/ywww/debug/phpDebug', | |
| 211 "Caught one?: ".$searchparameterdata, | |
| 212 FILE_APPEND); | |
| 213 file_put_contents('/var/ywww/debug/phpDebug', | |
| 214 print_r($output, TRUE)."\n", | |
| 215 FILE_APPEND); | |
| 216 } ); | |
| 217 $review = $xml->Items->Item->CustomerReviews->IFrameURL; | |
| 218 // The above is failing repeatedly -- | |
| 219 //PHP Notice: Trying to get property of non-object in | |
| 220 // /var/ywww/xml/getAmazonInfo.php on line [109] | |
| 221 // See the dumped structure at the end of this file for the | |
| 222 // cause | |
| 223 restore_error_handler(); | |
| 224 //echo $review; | |
| 225 } | |
| 226 if ($review != "") | |
| 227 { | |
| 228 $text = @file_get_contents($review . "&truncate=300"); | |
| 229 $removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text); | |
| 230 $removeTop2 = preg_replace('~<div class="crIFrameHeaderHistogram">(.*?)<div class="crIframeReviewList">~si', '', $text); | |
| 231 if (preg_match('~<body[^>]*>(.*?)</body>~si', $removeTop2, $body)){ $getBody = trim($body[1]); } else { $getBody = $removeTop2;} | |
| 232 $removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody); | |
| 233 $removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv); | |
| 234 $setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs); | |
| 235 //replace <!-- BOUNDARY --> with BOTTOM-TOP | |
| 236 $remove1 = '~<table cellpadding="0"(.*?)%">~s'; | |
| 237 $setBoundary = preg_replace($remove1,'', $setBoundary); | |
| 238 $remove2 = '~</td><td bg(.*?)</table>~s'; | |
| 239 $setBoundary = preg_replace($remove2,'', $setBoundary); | |
| 240 $remove3 = '~<a name=(.*?)</a>~s'; | |
| 241 $setBoundary = preg_replace($remove3,'', $setBoundary); | |
| 242 $setBoundary2 = str_replace('<br />','', $setBoundary); | |
| 243 //remove all extra crap; | |
| 244 $setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2); | |
| 245 //replace </td> with BOTTOM | |
| 246 | |
| 247 if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews)) | |
| 248 { | |
| 249 $reviewContents = $reviews[1]; | |
| 250 //print_r($reviewContents); | |
| 251 $review1 = trim($reviewContents[0]); | |
| 252 $review1 = str_replace("\n", "", $review1); | |
| 253 $review1 = str_replace("\r", "", $review1); | |
| 254 if (isset($reviewContents[1])) { | |
| 255 $review2 = trim($reviewContents[1]); | |
| 256 $review2 = str_replace("\n", "", $review2); | |
| 257 $review2 = str_replace("\r", "", $review2); | |
|
7
1dfe64e365a0
a bit more debugging/bomb-proofing
Robert Boland <robert@markup.co.uk>
parents:
5
diff
changeset
|
258 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
259 else { |
| 32 | 260 $review2 = ""; |
| 261 } | |
| 262 if (isset($reviewContents[2])) { | |
| 263 $review3 = trim($reviewContents[2]); | |
| 264 $review3 = str_replace("\n", "", $review3); | |
| 265 $review3 = str_replace("\r", "", $review3); | |
| 266 } | |
| 267 else { | |
| 268 $review3 = ""; | |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
269 } |
| 5 | 270 } |
| 32 | 271 else |
| 272 { | |
| 273 $review1 = ""; | |
| 274 $review2 = ""; | |
| 275 $review3 = ""; | |
| 276 //echo "EPIC FAIL"; | |
| 277 } | |
| 278 | |
| 279 unset($xml->Items->Item->CustomerReviews); | |
| 280 $xdoc = new DomDocument; | |
| 281 $xdoc->loadXML($xml->asXML()); | |
| 282 | |
| 283 $cReviews = $xdoc ->createElement('CustomerReviews'); | |
| 284 $cReviewHolder = $xdoc ->createElement('Review'); | |
| 285 $cReview = $xdoc ->createElement('Content'); | |
| 286 $cReviewHolder2 = $xdoc ->createElement('Review'); | |
| 287 $cReview2 = $xdoc ->createElement('Content'); | |
| 288 $cReviewHolder3 = $xdoc ->createElement('Review'); | |
| 289 $cReview3 = $xdoc ->createElement('Content'); | |
| 290 | |
| 291 $txtNode = $xdoc ->createTextNode ($review1); | |
| 292 $cReview -> appendChild($txtNode); | |
| 293 | |
| 294 $txtNode2 = $xdoc ->createTextNode ($review2); | |
| 295 $cReview2 -> appendChild($txtNode2); | |
| 296 | |
| 297 $txtNode3 = $xdoc ->createTextNode ($review3); | |
| 298 $cReview3 -> appendChild($txtNode3); | |
| 299 | |
| 300 $cReviewHolder -> appendChild($cReview); | |
| 301 $cReviewHolder2 -> appendChild($cReview2); | |
| 302 $cReviewHolder3 -> appendChild($cReview3); | |
| 303 | |
| 304 $cReviews -> appendChild($cReviewHolder); | |
| 305 $cReviews -> appendChild($cReviewHolder2); | |
| 306 $cReviews -> appendChild($cReviewHolder3); | |
| 307 | |
| 308 $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews); | |
| 309 $newXML = simplexml_import_dom($xdoc); | |
| 310 $output = $newXML->asXml(); | |
| 311 } | |
| 312 | |
| 313 if($go == 1) { | |
| 314 $item = $xml->Items->Item[0]; | |
| 315 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) { | |
| 316 $title = $item->ItemAttributes->Title; } | |
| 317 else { $title = "[no title]"; }; | |
| 318 file_put_contents('/var/ywww/debug/phpDebug',"win: |$errorCode| ". | |
| 319 $title."\n", | |
| 320 FILE_APPEND); | |
| 321 return $output; | |
| 322 } | |
| 323 else | |
| 324 { | |
| 325 if ($xml->Items->Item) { | |
| 326 $title = $xml->Items->Item[0]->ItemAttributes->Title; | |
| 327 $author = $xml->Items->Item[0]->ItemAttributes->Author; | |
| 328 $binding = $xml->Items->Item[0]->ItemAttributes->Binding; | |
| 329 $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber; | |
| 330 if($dewey == "") | |
| 331 $dewey = "null"; | |
| 332 $imageURL = $xml->Items->Item[0]->MediumImage->URL; | |
| 333 $salesRank = $xml->Items->Item[0]->SalesRank; | |
| 334 $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate; | |
| 335 if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";} | |
| 336 if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";} | |
| 337 if (strlen($pubDate)==0) { | |
| 338 $pubDate="null"; | |
| 339 } | |
| 5 | 340 else { |
| 32 | 341 $pubDate="\"$pubDate\""; |
| 342 } | |
| 343 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; | |
| 344 } | |
| 345 else { | |
| 346 $title = $salesRank = ""; | |
| 347 $dewey = "null"; | |
| 348 } | |
| 349 | |
| 350 $genreID = ""; | |
| 351 $genre = ""; | |
| 352 $genArr = array(); | |
| 353 | |
| 354 if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) { | |
| 355 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ | |
| 356 //sexy recursive function | |
| 357 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); | |
| 358 | |
| 359 if($genre != "") | |
| 360 $genArr[strval($genreID)] = strval($genre); | |
| 361 //$genArr[$i] = array(strval($genreID) => strval($genre)); | |
| 362 | |
| 363 //echo $genre; | |
| 364 //echo $genreID; | |
| 365 | |
| 366 $genre = ""; | |
| 367 $genreID = ""; | |
| 5 | 368 } |
| 32 | 369 } |
| 370 | |
| 371 $g1 = "null"; | |
| 372 $g2 = "null"; | |
| 373 $g3 = "null"; | |
| 374 $loop = 1; | |
| 375 | |
| 376 foreach ($genArr as $key => $value) { | |
| 377 //echo "$key => $value"; | |
| 378 if ($key>2047) { | |
| 379 //HST added | |
| 380 break; | |
| 381 } | |
| 382 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table | |
| 383 //echo $queryG; | |
| 384 include "../../private/db.php"; | |
| 385 $resG = mysqli_query($link, $queryG); | |
| 386 mysqli_close($link); | |
| 387 | |
| 388 switch ($loop) { | |
| 389 case 1: | |
| 390 $g1 = $key; | |
| 391 break; | |
| 392 case 2: | |
| 393 $g2 = $key; | |
| 394 break; | |
| 395 case 3: | |
| 396 $g3 = $key; | |
| 397 break; | |
| 398 } | |
| 399 | |
| 400 $loop++; | |
| 401 } | |
| 402 | |
| 403 if($salesRank == "") | |
| 404 $salesRank = "null"; | |
| 405 | |
| 406 if($title != "") | |
| 4 | 407 { |
| 32 | 408 include "../../private/db.php"; |
| 409 if ($publisher->count()==0) { | |
| 410 $publisher="null"; | |
| 411 } | |
| 412 else { | |
| 413 $publisher=mysqli_real_escape_string($link,$publisher); | |
| 414 if (strlen($publisher)>30) { | |
| 415 $publisher=rtrim(substr($publisher,0,30),"\\"); | |
| 416 } | |
| 417 $publisher="\"".$publisher."\""; | |
| 418 } | |
| 419 if ($author->count()==0) { | |
| 420 $author="unknown"; | |
| 5 | 421 } |
| 32 | 422 else { |
| 423 $author=mysqli_real_escape_string($link,$author); | |
| 424 if (strlen($author)>30) { | |
| 425 $author=rtrim(substr($author,0,30),"\\"); | |
| 426 } | |
| 427 } | |
| 428 $author="\"".$author."\""; | |
| 429 $title=mysqli_real_escape_string($link,$title); | |
| 430 if (strlen($title)>100) { | |
| 431 $title=rtrim(substr($title,0,100),"\\"); | |
| 432 } | |
| 433 $title="\"".$title."\""; | |
| 434 $review1 = mysqli_real_escape_string($link,$review1); | |
| 435 if (strlen($review1)>500) { $review1=rtrim(substr($review1,0,500),"\\");} | |
| 436 $review2 = mysqli_real_escape_string($link,$review2); | |
| 437 if (strlen($review2)>500) { $review2=rtrim(substr($review2,0,500),"\\");} | |
| 438 $review3 = mysqli_real_escape_string($link,$review3); | |
| 439 if (strlen($review3)>500) { $review3=rtrim(substr($review3,0,500),"\\");} | |
| 4 | 440 |
| 32 | 441 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",$title, $author,\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,$publisher,$g1,$g2,$g3,$loc)"; |
| 442 //echo $queryInsert; | |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
443 |
| 32 | 444 $res = mysqli_query($link, $queryInsert); |
| 445 if (!$res) { | |
| 446 $err=mysqli_error( $link ); | |
| 447 mysqli_close($link); | |
| 448 file_put_contents('/var/ywww/debug/phpDebug', | |
| 449 "anb failed: $queryInsert\n$err\n", | |
| 450 FILE_APPEND); | |
| 451 exit($err); | |
| 452 } | |
| 453 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; | |
| 454 if($review1 != "") { | |
| 455 $res = mysqli_query($link, $queryInsertReviews); | |
| 456 if (!$res) { | |
| 457 $err=mysqli_error( $link ); | |
| 458 mysqli_close($link); | |
| 459 file_put_contents('/var/ywww/debug/phpDebug', | |
| 460 "anr failed: $queryInsertReviews\n", | |
| 461 FILE_APPEND); | |
| 462 exit($err); | |
| 19 | 463 } |
| 32 | 464 } |
| 465 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
| 4 | 466 } |
| 32 | 467 |
| 468 echo $output; | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 function getAmazonDetLocal($go,$language,$loc, | |
| 473 $page,$operation,$searchparameter, | |
| 474 $searchparameterdata, | |
| 475 $show_array,$show_url,$show_xml) | |
| 476 { | |
| 477 global $output; | |
| 478 //look up info from db | |
| 479 include "../../private/db.php"; | |
| 480 $query = "CALL b_getBookInfo('$searchparameterdata', $loc)"; | |
| 481 //echo $query; | |
| 482 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); | |
| 4 | 483 |
| 32 | 484 $output = ""; |
| 485 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
| 486 $output .= "<Details>"; | |
| 487 if ( mysqli_num_rows( $res ) > 0 ) | |
| 488 { | |
| 489 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); | |
| 490 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
| 491 $output .= "<ASIN>" . $searchparameterdata . "</ASIN>"; | |
| 492 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>"; | |
| 493 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>"; | |
| 494 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>"; | |
| 495 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>"; | |
| 496 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>"; | |
| 497 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>"; | |
| 498 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>"; | |
| 499 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>"; | |
| 500 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>"; | |
| 501 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>"; | |
| 502 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>"; | |
| 503 $output .= "<ProductGroup>Book</ProductGroup>"; | |
| 504 $output .= "<Error>AccountLimitExceeded</Error>"; | |
| 4 | 505 |
| 32 | 506 } |
| 507 else { | |
| 508 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
| 509 } | |
| 510 $output .= "</Details>"; | |
| 511 echo $output; | |
| 4 | 512 } |
| 513 | |
| 514 function findGenre($browseNode, &$ID, &$gen) | |
| 515 { | |
| 516 if($browseNode->Name == "Subjects") | |
| 517 { | |
| 518 return true; | |
| 519 } | |
| 520 else | |
| 521 { | |
| 522 if($browseNode->Ancestors->BrowseNode) | |
| 523 { | |
| 524 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true) | |
| 525 { | |
| 526 $gen = $browseNode->Name; | |
| 527 $ID = $browseNode->BrowseNodeId; | |
| 528 } | |
| 529 } | |
| 530 return false; | |
| 531 } | |
| 532 } | |
| 533 | |
| 534 if(!isset($ret)) | |
| 535 { | |
| 536 include "aws_signed_request.php"; | |
| 537 getAmazonDet('default',0,'us'); //will get overwritten | |
| 538 } | |
| 539 /*Caught oneSimpleXMLElement Object | |
| 540 ( | |
| 541 [OperationRequest] => SimpleXMLElement Object | |
| 542 ( | |
| 543 [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330 | |
| 544 [Arguments] => SimpleXMLElement Object | |
| 545 ( | |
| 546 [Argument] => Array | |
| 547 ( | |
| 548 [0] => SimpleXMLElement Object | |
| 549 ( | |
| 550 [@attributes] => Array | |
| 551 ( | |
| 552 [Name] => AWSAccessKeyId | |
|
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
11
diff
changeset
|
553 [Value] => AKIAIHTNWC7L6LOUY4LQ |
| 4 | 554 ) |
| 555 | |
| 556 ) | |
| 557 | |
| 558 [1] => SimpleXMLElement Object | |
| 559 ( | |
| 560 [@attributes] => Array | |
| 561 ( | |
| 562 [Name] => AssociateTag | |
| 563 [Value] => bookwhack-21 | |
| 564 ) | |
| 565 | |
| 566 ) | |
| 567 | |
| 568 [2] => SimpleXMLElement Object | |
| 569 ( | |
| 570 [@attributes] => Array | |
| 571 ( | |
| 572 [Name] => ItemId | |
| 573 [Value] => B004Q3Q3Y4 | |
| 574 ) | |
| 575 | |
| 576 ) | |
| 577 | |
| 578 [3] => SimpleXMLElement Object | |
| 579 ( | |
| 580 [@attributes] => Array | |
| 581 ( | |
| 582 [Name] => ItemPage | |
| 583 [Value] => 1 | |
| 584 ) | |
| 585 | |
| 586 ) | |
| 587 | |
| 588 [4] => SimpleXMLElement Object | |
| 589 ( | |
| 590 [@attributes] => Array | |
| 591 ( | |
| 592 [Name] => Operation | |
| 593 [Value] => ItemLookup | |
| 594 ) | |
| 595 | |
| 596 ) | |
| 597 | |
| 598 [5] => SimpleXMLElement Object | |
| 599 ( | |
| 600 [@attributes] => Array | |
| 601 ( | |
| 602 [Name] => ResponseGroup | |
| 603 [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes | |
| 604 ) | |
| 605 | |
| 606 ) | |
| 607 | |
| 608 [6] => SimpleXMLElement Object | |
| 609 ( | |
| 610 [@attributes] => Array | |
| 611 ( | |
| 612 [Name] => ReviewSort | |
| 613 [Value] => -HelpfulVotes | |
| 614 ) | |
| 615 | |
| 616 ) | |
| 617 | |
| 618 [7] => SimpleXMLElement Object | |
| 619 ( | |
| 620 [@attributes] => Array | |
| 621 ( | |
| 622 [Name] => Service | |
| 623 [Value] => AWSECommerceService | |
| 624 ) | |
| 625 | |
| 626 ) | |
| 627 | |
| 628 [8] => SimpleXMLElement Object | |
| 629 ( | |
| 630 [@attributes] => Array | |
| 631 ( | |
| 632 [Name] => Timestamp | |
| 633 [Value] => 2016-12-15T23:12:34Z | |
| 634 ) | |
| 635 | |
| 636 ) | |
| 637 | |
| 638 [9] => SimpleXMLElement Object | |
| 639 ( | |
| 640 [@attributes] => Array | |
| 641 ( | |
| 642 [Name] => Version | |
| 643 [Value] => 2011-08-01 | |
| 644 ) | |
| 645 | |
| 646 ) | |
| 647 | |
| 648 [10] => SimpleXMLElement Object | |
| 649 ( | |
| 650 [@attributes] => Array | |
| 651 ( | |
| 652 [Name] => Signature | |
| 653 [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ= | |
| 654 ) | |
| 655 | |
| 656 ) | |
| 657 | |
| 658 ) | |
| 659 | |
| 660 ) | |
| 661 | |
| 662 [RequestProcessingTime] => 0.3518217620000000 | |
| 663 ) | |
| 664 | |
| 665 [Items] => SimpleXMLElement Object | |
| 666 ( | |
| 667 [Request] => SimpleXMLElement Object | |
| 668 ( | |
| 669 [IsValid] => True | |
| 670 [ItemLookupRequest] => SimpleXMLElement Object | |
| 671 ( | |
| 672 [IdType] => ASIN | |
| 673 [ItemId] => B004Q3Q3Y4 | |
| 674 [ResponseGroup] => Array | |
| 675 ( | |
| 676 [0] => ItemAttributes | |
| 677 [1] => Reviews | |
| 678 [2] => EditorialReview | |
| 679 [3] => OfferSummary | |
| 680 [4] => Offers | |
| 681 [5] => Images | |
| 682 [6] => AlternateVersions | |
| 683 [7] => SalesRank | |
| 684 [8] => BrowseNodes | |
| 685 ) | |
| 686 | |
| 687 [VariationPage] => All | |
| 688 ) | |
| 689 | |
| 690 [Errors] => SimpleXMLElement Object | |
| 691 ( | |
| 692 [Error] => SimpleXMLElement Object | |
| 693 ( | |
| 694 [Code] => AWS.InvalidParameterValue | |
| 695 [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request. | |
| 696 ) | |
| 697 | |
| 698 ) | |
| 699 | |
| 700 ) | |
| 701 | |
| 702 ) | |
| 703 | |
| 704 ) | |
| 705 */ | |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
706 /*$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2009-03-31/\"><Error><Code>AccountLimitExceeded</Code><Message>Account limit of 2056 requests per hour exceeded.</Message></Error><RequestID>290ed059-730c-4789-93b4-6d21e11053d3</RequestID></ItemLookupErrorResponse>");*/ |
| 4 | 707 ?> |
