scraper update
This commit is contained in:
@@ -48,7 +48,10 @@ try {
|
||||
'color' => $filament['color'],
|
||||
'amazonUrl' => $filament['amazonUrl'],
|
||||
'prices' => [],
|
||||
'currentDiscount' => $filament['currentDiscount'] ? json_decode($filament['currentDiscount'], true) : null // Decode JSON format
|
||||
'currentDiscount' => $filament['currentDiscount'] ? json_decode($filament['currentDiscount'], true) : [
|
||||
'discount' => ['value' => 0, 'type' => 'none'],
|
||||
'voucher' => ['value' => 0, 'type' => 'none']
|
||||
] // Decode JSON format and provide fallback
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,17 @@ try {
|
||||
$scrapedData = scrapeAmazonData($amazonUrl);
|
||||
|
||||
if ($scrapedData && $scrapedData['price'] > 0) {
|
||||
$currentDiscount = json_encode($scrapedData['voucher']); // Encode discount as JSON
|
||||
// Prepare currentDiscount JSON structure with the correct format
|
||||
$currentDiscount = json_encode([
|
||||
'discount' => [
|
||||
'value' => $scrapedData['currentDiscount']['discount']['value'] ?? 0,
|
||||
'type' => $scrapedData['currentDiscount']['discount']['type'] ?? 'percentage',
|
||||
],
|
||||
'voucher' => [
|
||||
'value' => $scrapedData['currentDiscount']['voucher']['value'] ?? 0,
|
||||
'type' => $scrapedData['currentDiscount']['voucher']['type'] ?? null,
|
||||
],
|
||||
]);
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO filamentPriceHistory (filamentId, price, currentDiscount)
|
||||
@@ -30,7 +40,7 @@ try {
|
||||
':currentDiscount' => $currentDiscount
|
||||
]);
|
||||
|
||||
echo "Updated price for {$filament['filamentName']}: £{$scrapedData['price']}, Discount: " . json_encode($scrapedData['voucher']) . "\n";
|
||||
echo "Updated price for {$filament['filamentName']}: £{$scrapedData['price']}, Current Discount: {$currentDiscount}\n";
|
||||
} else {
|
||||
echo "Failed to update {$filament['filamentName']} (no price found or £0).\n";
|
||||
}
|
||||
@@ -41,4 +51,3 @@ try {
|
||||
} catch (PDOException $e) {
|
||||
echo "Database error: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user