Update: 2026-06-30 20:54:00

This commit is contained in:
Hamza-Ayed
2026-06-30 20:54:00 +03:00
parent 1f1a3385e3
commit c2eab19045

View File

@@ -38,25 +38,44 @@ $insertedCount = 0;
$stmt = $con->prepare("INSERT INTO scraped_competitor_prices (task_id, app_name, start_location, end_location, price_amount, currency) VALUES (?, ?, ?, ?, ?, ?)");
foreach ($data as $row) {
$taskId = $row['task_id'] ?? null;
$appName = $row['app'] ?? 'Unknown';
$startLoc = $row['start_location'] ?? '';
$endLoc = $row['end_location'] ?? '';
$priceStr = $row['price'] ?? '';
if (isset($row['status']) && $row['status'] !== 'success') {
continue;
}
$taskId = $row['task_id'] ?? null;
$resultData = $row['result_data'] ?? [];
$appName = $resultData['app'] ?? $row['app'] ?? 'Unknown';
$startLoc = $resultData['start_location'] ?? $row['start_location'] ?? '';
if (empty($startLoc) && !empty($resultData['start_lat'])) {
$startLoc = "Lat: {$resultData['start_lat']}, Lng: {$resultData['start_lng']}";
}
$endLoc = $resultData['end_location'] ?? $row['end_location'] ?? '';
if (empty($endLoc) && !empty($resultData['end_lat'])) {
$endLoc = "Lat: {$resultData['end_lat']}, Lng: {$resultData['end_lng']}";
}
$priceRaw = $resultData['price'] ?? $row['price'] ?? 0;
// Extract numeric amount and currency from string like "2.5 JOD"
$amount = 0.0;
$currency = 'JOD';
// Match numeric parts (including decimals) and text parts
if (preg_match('/([\d\.]+)\s*([A-Za-z]+|د\.ا)/', $priceStr, $matches)) {
$amount = (float)$matches[1];
$currency = $matches[2];
if ($currency === 'د.ا') {
$currency = 'JOD';
}
if (is_numeric($priceRaw)) {
$amount = (float)$priceRaw;
} else {
$amount = (float)$priceStr;
$priceStr = (string)$priceRaw;
// Match numeric parts (including decimals) and text parts
if (preg_match('/([\d\.]+)\s*([A-Za-z]+|د\.ا)/', $priceStr, $matches)) {
$amount = (float)$matches[1];
$currency = $matches[2];
if ($currency === 'د.ا') {
$currency = 'JOD';
}
} else {
$amount = (float)$priceStr;
}
}
// Ignore invalid entries without an amount
@@ -66,6 +85,8 @@ foreach ($data as $row) {
if ($stmt->execute([$taskId, $appName, $startLoc, $endLoc, $amount, $currency])) {
$insertedCount++;
} else {
echo "Failed to insert task_id: $taskId. Error: " . implode(" ", $stmt->errorInfo()) . "\n";
}
}