Mercurial > hg > ywww
comparison php/read/getBookDetails.php @ 43:dbc006408d2b
ASSUMES we have SetEnv PHP_VALUE "include_path =.:/var/test/private:/var/test/ywww:/usr/share/php" in apache2/.../test.conf
use dl(...) for debug logging, defined in dlog.php
use doAmazonRequest in amazonBookSearch
use ../private/web.php (q.v., not in mercurial) for Aserver and Aassociates
Started by updating from 40:c24ae74bf6d5, i.e. just before the bug on the main line
| author | Charlie Root |
|---|---|
| date | Sat, 05 Jan 2019 18:00:10 -0500 |
| parents | c24ae74bf6d5 |
| children | 38d209611508 |
comparison
equal
deleted
inserted
replaced
| 42:3f400072bf14 | 43:dbc006408d2b |
|---|---|
| 1 <?php | 1 <?php |
| 2 | 2 include_once "dlog.php"; |
| 3 | |
| 4 include_once "web.php"; | |
| 3 function findGenre($browseNode, &$ID, &$gen) | 5 function findGenre($browseNode, &$ID, &$gen) |
| 4 { | 6 { |
| 5 if($browseNode->Name == "Subjects") | 7 if($browseNode->Name == "Subjects") |
| 6 { | 8 { |
| 7 return true; | 9 return true; |
| 21 } | 23 } |
| 22 return false; | 24 return false; |
| 23 } | 25 } |
| 24 } | 26 } |
| 25 | 27 |
| 26 global $out,$isbn; | 28 global $out,$isbn,$Aserver,$Aassociates_id; |
| 27 if(isset($_GET['isbn'])){ | 29 if(isset($_GET['isbn'])){ |
| 28 $isbn = $_GET['isbn']; | 30 $isbn = $_GET['isbn']; |
| 29 if(isset($_GET['locale'])){ | 31 if(isset($_GET['locale'])){ |
| 30 $locale=$_GET['locale']; | 32 $locale=$_GET['locale']; |
| 31 | 33 |
| 104 | 106 |
| 105 if($proceed == true) | 107 if($proceed == true) |
| 106 { | 108 { |
| 107 include "aws_signed_request.php"; | 109 include "aws_signed_request.php"; |
| 108 include_once "../../xml/doAmazonRequest.inc"; | 110 include_once "../../xml/doAmazonRequest.inc"; |
| 109 file_put_contents('/var/ywww/debug/phpDebug', | 111 dl("nbd proceeding: $isbn\n"); |
| 110 "nbd proceeding: $isbn\n", | |
| 111 FILE_APPEND); | |
| 112 | 112 |
| 113 //book does not exist already so look up all the info from browse nodes.... | 113 //book does not exist already so look up all the info from browse nodes.... |
| 114 | 114 |
| 115 $Adefault=array( | 115 $Adefault=array( |
| 116 'language' =>'en', //what language to render the page in | 116 'language' =>'en', //what language to render the page in |
| 126 'show_url' =>false, //debug: show XML request url to be send to Amazon? | 126 'show_url' =>false, //debug: show XML request url to be send to Amazon? |
| 127 'show_xml' =>false, //debug: show incoming XML code from Amazon? | 127 'show_xml' =>false, //debug: show incoming XML code from Amazon? |
| 128 ); | 128 ); |
| 129 //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 | 129 //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 |
| 130 | 130 |
| 131 $Aassociates_id=array( | |
| 132 'uk' => 'bookwhack-21', | |
| 133 'us' => 'your02b-20', | |
| 134 'ca' => 'book009-20', | |
| 135 'de' => 'book04c-21', | |
| 136 'fr' => 'book07f-21', | |
| 137 ); | |
| 138 | |
| 139 $Aserver=array( | |
| 140 'ca' => array( | |
| 141 'ext' => 'ca' , //Canadian normal server | |
| 142 'nor' => 'http://www.amazon.ca' , //Canadian normal server | |
| 143 'xml' => 'http://xml.amazon.com' , //Canadian xml server | |
| 144 ), | |
| 145 'de' => array( | |
| 146 'ext' => 'de' , //German normal server | |
| 147 'nor' => 'http://www.amazon.de' , //German normal server | |
| 148 'xml' => 'http://xml-eu.amazon.com', //German xml server | |
| 149 ), | |
| 150 'fr' => array( | |
| 151 'ext' => 'fr' , //French normal server | |
| 152 'nor' => 'http://www.amazon.fr' , //French normal server | |
| 153 'xml' => 'http://xml-eu.amazon.com', //French xml server | |
| 154 ), | |
| 155 'jp' => array( | |
| 156 'ext' => 'jp' , //Japanese normal server, not co.jp! | |
| 157 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server | |
| 158 'xml' => 'http://xml.amazon.com' , //Japanese xml server | |
| 159 ), | |
| 160 'uk' => array( | |
| 161 'ext' => 'co.uk' , //UK normal server | |
| 162 'nor' => 'http://www.amazon.co.uk' , //UK normal server | |
| 163 'xml' => 'http://xml-eu.amazon.com', //UK xml server | |
| 164 ), | |
| 165 'us' => array( | |
| 166 'ext' => 'com' , //USA normal server | |
| 167 'nor' => 'http://www.amazon.com' , //USA normal server | |
| 168 'xml' => 'http://xml.amazon.com' , //USA xml server | |
| 169 ), | |
| 170 ); | |
| 171 | 131 |
| 172 //for all parameters see if the user has overruled it or use the default | 132 //for all parameters see if the user has overruled it or use the default |
| 173 foreach ($Adefault as $i=>$d) { | 133 foreach ($Adefault as $i=>$d) { |
| 174 $$i=isset($_GET[$i])?$_GET[$i]:$d; | 134 $$i=isset($_GET[$i])?$_GET[$i]:$d; |
| 175 } | 135 } |
| 190 try { | 150 try { |
| 191 $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,6,'d'); | 151 $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,6,'d'); |
| 192 //use this xml to pull out the necessary information and save it | 152 //use this xml to pull out the necessary information and save it |
| 193 set_error_handler(function () { | 153 set_error_handler(function () { |
| 194 global $out,$isbn; | 154 global $out,$isbn; |
| 195 file_put_contents('/var/ywww/debug/phpDebug', | 155 dl("Caught one bd: $isbn\n"); |
| 196 "Caught one bd: ".$isbn, | 156 dl(print_r($out, TRUE)."\n"); |
| 197 FILE_APPEND); | |
| 198 file_put_contents('/var/ywww/debug/phpDebug', | |
| 199 print_r($out, TRUE)."\n", | |
| 200 FILE_APPEND); | |
| 201 } ); | 157 } ); |
| 202 include "../../../private/db.php"; | 158 include "db.php"; |
| 203 | 159 |
| 204 $title=""; | 160 $title=""; |
| 205 $author=""; | 161 $author=""; |
| 206 $binding=""; | 162 $binding=""; |
| 207 $dewey=""; | 163 $dewey=""; |
| 315 | 271 |
| 316 $res = mysqli_query($link, $queryInsert); | 272 $res = mysqli_query($link, $queryInsert); |
| 317 if (!$res) { | 273 if (!$res) { |
| 318 $err=mysqli_error( $link ); | 274 $err=mysqli_error( $link ); |
| 319 mysqli_close($link); | 275 mysqli_close($link); |
| 320 file_put_contents('/var/ywww/debug/phpDebug', | 276 dl("anb failed: $err, $pubDate, $g2, $publisher, $title\n"); |
| 321 "anb failed: $err, $pubDate, $g2, $publisher, $title\n", | |
| 322 FILE_APPEND); | |
| 323 exit($err); | 277 exit($err); |
| 324 } | 278 } |
| 325 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | 279 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 326 | 280 |
| 327 | 281 |
| 338 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; | 292 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; |
| 339 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; | 293 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; |
| 340 $output .= "<ProductGroup>Book</ProductGroup>"; | 294 $output .= "<ProductGroup>Book</ProductGroup>"; |
| 341 } | 295 } |
| 342 catch (Exception $e) { | 296 catch (Exception $e) { |
| 343 file_put_contents('/var/ywww/debug/phpDebug', | 297 dl("gBD: dAR failed:".$e->getMessage()."\n"); |
| 344 "gBD: dAR failed:".$e->getMessage()."\n", | |
| 345 FILE_APPEND); | |
| 346 } | 298 } |
| 347 } | 299 } |
| 348 $output .= "</BookDetails>"; | 300 $output .= "</BookDetails>"; |
| 349 | 301 |
| 350 echo $output; | 302 echo $output; |
