annotate xml/getAmazonInfo.php @ 33:c9d9b76ecbf9

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