Mercurial > hg > ywww
comparison php/read/getBookDetails.php @ 13:b78209a5fba1
Merge
| author | Rob Boland <robert@metail.co.uk> |
|---|---|
| date | Sat, 18 Feb 2017 15:18:47 +0000 |
| parents | 5aa24c984a3b |
| children | 385ddd7c4b55 ae1459564f66 |
comparison
equal
deleted
inserted
replaced
| 12:970a4834afff | 13:b78209a5fba1 |
|---|---|
| 187 //'SearchIndex' =>$searchindex , //Books for example. | 187 //'SearchIndex' =>$searchindex , //Books for example. |
| 188 $parameters['SearchIndex']=$searchindex; | 188 $parameters['SearchIndex']=$searchindex; |
| 189 } | 189 } |
| 190 | 190 |
| 191 | 191 |
| 192 file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ". | |
| 193 print_r($parameters,TRUE)."\n",FILE_APPEND); | |
| 194 | |
| 195 $ext=$Aserver[$locale]['ext']; | 192 $ext=$Aserver[$locale]['ext']; |
| 196 $file_data=$ext; | 193 $file_data=$ext; |
| 197 ksort($parameters); | 194 ksort($parameters); |
| 198 foreach ($parameters as $i=>$d) { | 195 foreach ($parameters as $i=>$d) { |
| 199 $file_data.='&'.$i.'='.$d; | 196 $file_data.='&'.$i.'='.$d; |
| 211 $out = curl_exec($crl); | 208 $out = curl_exec($crl); |
| 212 curl_close($crl); | 209 curl_close($crl); |
| 213 | 210 |
| 214 //echo $out; | 211 //echo $out; |
| 215 | 212 |
| 216 if (preg_match("<Error>",$out)) { | 213 if (preg_match("<Error>",$out)) { |
| 217 $xml = new SimpleXMLElement($out); | 214 $xml = new SimpleXMLElement($out); |
| 218 $resName=$xml->getName(); | 215 $resName=$xml->getName(); |
| 219 $code=$xml->Error->Code; | 216 $code=$xml->Error->Code; |
| 220 file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, ". | 217 file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND); |
| 221 $xml->Error->Code."\n",FILE_APPEND); | 218 if ($code=='RequestThrottled') { |
| 222 } | 219 usleep(200000); // Try to reduce throttling until we get a |
| 223 else { | 220 // principled solution in place |
| 224 $xml = new SimpleXMLElement($out); | 221 } |
| 225 //use this xml to pull out the necessary information and save it | 222 else { |
| 226 set_error_handler(function () { | 223 file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ". |
| 227 global $out,$isbn; | 224 print_r($parameters,TRUE)."\n",FILE_APPEND); |
| 228 file_put_contents('/var/ywww/debug/phpDebug', | 225 if ($code=="") { |
| 229 "Caught one bd: ".$isbn, | 226 file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$out\n",FILE_APPEND); |
| 230 FILE_APPEND); | 227 } |
| 231 file_put_contents('/var/ywww/debug/phpDebug', | 228 } |
| 232 print_r($out, TRUE)."\n", | 229 } |
| 233 FILE_APPEND); | 230 else { |
| 234 } ); | 231 $xml = new SimpleXMLElement($out); |
| 235 | 232 //use this xml to pull out the necessary information and save it |
| 236 $title=""; | 233 set_error_handler(function () { |
| 237 $author=""; | 234 global $out,$isbn; |
| 238 $binding=""; | 235 file_put_contents('/var/ywww/debug/phpDebug', |
| 239 $dewey=""; | 236 "Caught one bd: ".$isbn, |
| 240 $imageURL=""; | 237 FILE_APPEND); |
| 241 $salesRank=""; | 238 file_put_contents('/var/ywww/debug/phpDebug', |
| 242 $pubDate=""; | 239 print_r($out, TRUE)."\n", |
| 243 $publisher=""; | 240 FILE_APPEND); |
| 244 | 241 } ); |
| 245 $title = $xml->Items->Item->ItemAttributes->Title; | 242 |
| 246 $author = $xml->Items->Item->ItemAttributes->Author; | 243 $title=""; |
| 247 $binding = $xml->Items->Item->ItemAttributes->Binding; | 244 $author=""; |
| 248 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; | 245 $binding=""; |
| 249 if($dewey == "") | 246 $dewey=""; |
| 250 $dewey = "null"; | 247 $imageURL=""; |
| 251 $imageURL = $xml->Items->Item->MediumImage->URL; | 248 $salesRank=""; |
| 252 $salesRank = $xml->Items->Item->SalesRank; | 249 $pubDate=""; |
| 253 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; | 250 $publisher=""; |
| 254 $publisher = $xml->Items->Item->ItemAttributes->Publisher; | 251 |
| 255 restore_error_handler(); | 252 $title = $xml->Items->Item->ItemAttributes->Title; |
| 256 /*echo $title; | 253 $author = $xml->Items->Item->ItemAttributes->Author; |
| 257 echo $author; | 254 $binding = $xml->Items->Item->ItemAttributes->Binding; |
| 258 echo $binding; | 255 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; |
| 259 echo $dewey; | 256 if($dewey == "") |
| 260 echo $imageURL; | 257 $dewey = "null"; |
| 261 echo $salesRank; | 258 $imageURL = $xml->Items->Item->MediumImage->URL; |
| 262 echo $pubDate; | 259 $salesRank = $xml->Items->Item->SalesRank; |
| 263 echo $publisher;*/ | 260 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; |
| 264 | 261 $publisher = $xml->Items->Item->ItemAttributes->Publisher; |
| 265 $genreID = ""; | 262 restore_error_handler(); |
| 266 $genre = ""; | 263 /*echo $title; |
| 267 $genArr = array(); | 264 echo $author; |
| 268 $g1 = "null"; | 265 echo $binding; |
| 269 $g2 = "null"; | 266 echo $dewey; |
| 270 $g3 = "null"; | 267 echo $imageURL; |
| 271 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ | 268 echo $salesRank; |
| 272 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ | 269 echo $pubDate; |
| 273 //sexy recursive function | 270 echo $publisher;*/ |
| 274 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); | 271 |
| 275 | 272 $genreID = ""; |
| 276 if($genre != "") | 273 $genre = ""; |
| 277 $genArr[strval($genreID)] = strval($genre); | 274 $genArr = array(); |
| 278 //$genArr[$i] = array(strval($genreID) => strval($genre)); | 275 $g1 = "null"; |
| 279 | 276 $g2 = "null"; |
| 280 //echo $genre; | 277 $g3 = "null"; |
| 281 //echo $genreID; | 278 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ |
| 282 | 279 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ |
| 283 $genre = ""; | 280 //sexy recursive function |
| 284 $genreID = ""; | 281 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); |
| 285 } | 282 |
| 286 | 283 if($genre != "") |
| 287 $g1 = "null"; | 284 $genArr[strval($genreID)] = strval($genre); |
| 288 $g2 = "null"; | 285 //$genArr[$i] = array(strval($genreID) => strval($genre)); |
| 289 $g3 = "null"; | 286 |
| 290 $loop = 1; | 287 //echo $genre; |
| 291 | 288 //echo $genreID; |
| 292 foreach ($genArr as $key => $value) { | 289 |
| 293 //echo "$key => $value"; | 290 $genre = ""; |
| 294 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table | 291 $genreID = ""; |
| 295 //echo $queryG; | 292 } |
| 296 $resG = mysqli_query($link, $queryG); | 293 |
| 297 | 294 $g1 = "null"; |
| 298 switch ($loop) { | 295 $g2 = "null"; |
| 299 case 1: | 296 $g3 = "null"; |
| 300 $g1 = $key; | 297 $loop = 1; |
| 301 break; | 298 |
| 302 case 2: | 299 foreach ($genArr as $key => $value) { |
| 303 $g2 = $key; | 300 //echo "$key => $value"; |
| 304 break; | 301 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table |
| 305 case 3: | 302 //echo $queryG; |
| 306 $g3 = $key; | 303 $resG = mysqli_query($link, $queryG); |
| 307 break; | 304 |
| 308 } | 305 switch ($loop) { |
| 309 | 306 case 1: |
| 310 $loop++; | 307 $g1 = $key; |
| 311 } | 308 break; |
| 312 } | 309 case 2: |
| 313 | 310 $g2 = $key; |
| 314 if($salesRank == "") | 311 break; |
| 315 $salesRank = "null"; | 312 case 3: |
| 316 | 313 $g3 = $key; |
| 317 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | 314 break; |
| 318 include "../../../private/db.php"; | 315 } |
| 319 | 316 |
| 320 $title = strtr($title, '"', "'"); | 317 $loop++; |
| 321 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; | 318 } |
| 322 //echo $queryInsert; | 319 } |
| 323 | 320 |
| 324 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); | 321 if($salesRank == "") |
| 325 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | 322 $salesRank = "null"; |
| 326 | 323 |
| 327 | 324 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 328 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; | 325 include "../../../private/db.php"; |
| 329 $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; | 326 |
| 330 $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; | 327 $title = strtr($title, '"', "'"); |
| 331 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; | 328 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; |
| 332 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; | 329 //echo $queryInsert; |
| 333 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; | 330 |
| 334 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; | 331 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); |
| 335 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; | 332 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 336 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; | 333 |
| 337 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; | 334 |
| 338 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; | 335 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; |
| 339 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; | 336 $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; |
| 340 $output .= "<ProductGroup>Book</ProductGroup>"; | 337 $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; |
| 338 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; | |
| 339 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; | |
| 340 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; | |
| 341 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; | |
| 342 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; | |
| 343 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; | |
| 344 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; | |
| 345 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; | |
| 346 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; | |
| 347 $output .= "<ProductGroup>Book</ProductGroup>"; | |
| 341 } | 348 } |
| 342 } | 349 } |
| 343 | 350 |
| 344 $output .= "</BookDetails>"; | 351 $output .= "</BookDetails>"; |
| 345 | 352 |
