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