test for nuc

This commit is contained in:
2024-02-10 13:49:36 +01:00
parent bc7f73c3a0
commit e91f39c9e5
4 changed files with 27 additions and 26 deletions

View File

@@ -43,8 +43,8 @@ class CountryCompareController extends Controller
{
$requests = Http::pool(fn (Pool $pool) => [
$this->countries->each(function ($country) use ($pool, $ta_code) {
Log::info('Getting page {url}', [ 'url' => $country->search_url . $ta_code ] );
return $pool->as($country->country_code)->get($country->search_url . $ta_code);
Log::info('Getting page {url}', [ 'url' => $country->search_url . $ta_code[0] ] );
return $pool->as($country->country_code)->get($country->search_url . $ta_code[0] );
})
]);
return $requests;
@@ -68,7 +68,9 @@ class CountryCompareController extends Controller
if ($responses[$country] instanceof \Illuminate\Http\Client\Response && $responses[$country]->ok()) {
$response = $responses[$country]->body();
// dd($responses);
$response = (string) $responses[$country]->body();
//dd($response)
switch ($country) {
case "BG":
case "BY":
@@ -76,7 +78,7 @@ class CountryCompareController extends Controller
$prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response, $country);
break;
case "IS":
$prices[$country] = $this->parseJson_IS($code, (string) $response, $country);
$prices[$country] = $this->parseJson_IS($code,(string) $response, $country);
break;
case "TR":
$prices[$country] = $this->parseJson_TR((string) $response, $country);
@@ -104,7 +106,6 @@ class CountryCompareController extends Controller
public function parseJson($json_raw, $country)
{
try {
$json_values = array();
$json_decoded = json_decode($json_raw, true);
@@ -128,9 +129,6 @@ class CountryCompareController extends Controller
);
break;
}
} catch (\Exception $e) {
return [];
}
return $json_values;
}
@@ -165,29 +163,28 @@ class CountryCompareController extends Controller
public function parseJson_CY_GR_BG($code, $body , $country)
{
//echo "country: " . $country . ", code: " . $code . "<br>";
//Log::info('{country},{body},{code}',[$country, $body, $code]);
$body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284");
$dochtml = new \DOMDocument();
@$dochtml->loadHTML('<?xml encoding="UTF-8">' . $body);
$dochtml->loadHTML($body);
$xpath = new \DOMXpath($dochtml);
$price = null;
$c = ltrim($code, "0");
$json_values = array();
try {
$price = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-price')[0]->nodeValue;
$url_product = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-url')[0]->nodeValue;
} catch (\Exception $e) {
return [];
}
$price = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-price')[0]->nodeValue;
$url_product = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-url')[0]->nodeValue;
$price = floatval($price);
$json_values = array(
'url' => $url_product,
'tag' => null,
'price' => floatval($price),
'country' => $country,
'url_product' => $url_product,
'tag' => null,
'price' => floatval($price),
'price_eur' => 0
);
return $json_values;
@@ -205,7 +202,6 @@ class CountryCompareController extends Controller
$c = ltrim($code, "0");
$json_values = array();
try {
$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//p[@class="itemNormalPrice display-6"]/span')[0]->nodeValue;
if (is_null($price) || empty($price)) {
@@ -225,9 +221,6 @@ class CountryCompareController extends Controller
default:
$url_product = null;
}
} catch (\Exception $e) {
return [];
}
if (is_null($price) || empty($price)) {
$url_product = null;
@@ -249,6 +242,10 @@ class CountryCompareController extends Controller
{
//echo "country: " . $country . ", code: " . $code . "<br>";
//$body = file_get_contents("https://ikea.is/is/search/?q=80366284");
// $client = new \GuzzleHttp\Client();
// $res = $client->request('GET', 'https://ikea.is/is/search/?q=80366284');
// $body= $res->getBody()->getContents();
$dochtml = new \DOMDocument();
@$dochtml->loadHTML('<?xml encoding="UTF-8">' . $body);
@@ -280,7 +277,7 @@ class CountryCompareController extends Controller
$json_values = array(
'url' => $url_product,
'tag' => null,
'price' => $price,
'salesPrice' => $price,
'country' => $country,
);

View File

@@ -49,7 +49,7 @@ class ProductsCompareController extends Controller
if ($online == true) {
Log::info("ONLINE {codes} {countries}", ["codes" => $codes, "countries" => $countries, "online" => $online]);
$products = $this->countryCompareController->compare($countries, $cHash, $aCodes);
$products = $this->countryCompareController->compare($countries, $cHash, $codes);
} else {
$products = IkeaProducts::whereIn("code", $aCodes);
if (count($countries)) $products->whereIn("country", $countries);