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