function crawl_price($provider) { switch ($provider) { case 'Amazon': return crawl_amazon(); break; case 'Walmart': return crawl_walmart(); break; case 'Toysrus': return crawl_toysrus(); break; case 'BN': return crawl_bn(); break; case 'Target': return crawl_target(); break; case 'LegoShop': return crawl_lego(); break; default: # code... break; } }
<?php require_once "crawlers.php"; require_once "db_handler.php"; require_once "twitter_handler.php"; $LegoDB = pull_DBSet(array("ETitle", "USPrice", "Availability", "Badge"), null); $LegoInfo = crawl_lego(); $sortedItems = array(); foreach ($LegoInfo->{'Items'} as $item) { $id = intval($item->{'LegoID'}); $sortedItems[$id] = $item; } ksort($sortedItems); foreach ($sortedItems as $item) { if (isset($item->{'Price'})) { $price = floatval($item->{'Price'}); } else { $price = 0; } if (isset($item->{'Saleprice'})) { $salePrice = floatval($item->{'Saleprice'}); } else { $salePrice = 0; } //generate the csv echo $item->{'LegoID'} . ",\"" . $item->{'Availability'} . "\"," . $price . "," . $salePrice . ",\"" . $item->{'Title'} . "\"\n"; //update DB_Set if (isset($LegoDB[$item->{'LegoID'}])) { $dbitem = $LegoDB[$item->{'LegoID'}]; $arrfields = array(); if ($price > 0 && $dbitem->{'USPrice'} != $price) {