[AutoJMBridge] Fix content extraction (#3649)

* [AutoJMBridge] Fix content extraction

- Website changed, bridge was updated accordingly
- Added the function detectParameters
- Added the test array for the detectParameters function

* [AutoJMBridge] Fix test

Fix content of the TEST_DETECT_PARAMETERS array

* [AutoJMBridge] Update exaù^me value parameter

Example value was not valid anymore, so it was updated
This commit is contained in:
sysadminstory 2023-09-05 02:12:47 +02:00 committed by GitHub
parent 752098e0fa
commit 38b957398a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,12 +13,20 @@ class AutoJMBridge extends BridgeAbstract
'type' => 'text', 'type' => 'text',
'required' => true, 'required' => true,
'title' => 'URL d\'une recherche avec filtre de véhicules sans le http://www.autojm.fr/', 'title' => 'URL d\'une recherche avec filtre de véhicules sans le http://www.autojm.fr/',
'exampleValue' => 'recherche?brands[]=peugeot&ranges[]=peugeot-nouvelle-308-2021-5p' 'exampleValue' => 'recherche?brands[]=PEUGEOT&ranges[]=PEUGEOT 308'
], ],
] ]
]; ];
const CACHE_TIMEOUT = 3600; const CACHE_TIMEOUT = 3600;
const TEST_DETECT_PARAMETERS = [
'https://www.autojm.fr/recherche?brands%5B%5D=PEUGEOT&ranges%5B%5D=PEUGEOT%20308'
=> ['url' => 'recherche?brands%5B%5D=PEUGEOT&ranges%5B%5D=PEUGEOT%20308',
'context' => 'Afficher les offres de véhicules disponible sur la recheche AutoJM'
]
];
public function getIcon() public function getIcon()
{ {
return self::URI . 'favicon.ico'; return self::URI . 'favicon.ico';
@ -35,6 +43,17 @@ class AutoJMBridge extends BridgeAbstract
} }
} }
public function getURI()
{
switch ($this->queriedContext) {
case 'Afficher les offres de véhicules disponible sur la recheche AutoJM':
return self::URI . $this->getInput('url');
break;
default:
return self::URI;
}
}
public function collectData() public function collectData()
{ {
// Get the number of result for this search // Get the number of result for this search
@ -52,7 +71,7 @@ class AutoJMBridge extends BridgeAbstract
$data = json_decode($json); $data = json_decode($json);
$nb_results = $data->nbResults; $nb_results = $data->nbResults;
$total_pages = ceil($nb_results / 15); $total_pages = ceil($nb_results / 14);
// Limit the number of page to analyse to 10 // Limit the number of page to analyse to 10
for ($page = 1; $page <= $total_pages && $page <= 10; $page++) { for ($page = 1; $page <= $total_pages && $page <= 10; $page++) {
@ -66,8 +85,8 @@ class AutoJMBridge extends BridgeAbstract
$image = $car->find('div[class=card-car__header__img]', 0)->find('img', 0)->src; $image = $car->find('div[class=card-car__header__img]', 0)->find('img', 0)->src;
// Decode HTML attribute JSON data // Decode HTML attribute JSON data
$car_data = json_decode(html_entity_decode($car->{'data-layer'})); $car_data = json_decode(html_entity_decode($car->{'data-layer'}));
$car_model = $car->{'data-title'} . ' ' . $car->{'data-suptitle'}; $car_model = $car_data->title;
$availability = $car->find('div[class=card-car__modalites]', 0)->find('div[class=col]', 0)->plaintext; $availability = $car->find('div[class*=card-car__modalites]', 0)->find('div[class=col]', 0)->plaintext;
$warranty = $car->find('div[data-type=WarrantyCard]', 0)->plaintext; $warranty = $car->find('div[data-type=WarrantyCard]', 0)->plaintext;
$discount_html = $car->find('div[class=subtext vehicle_reference_element]', 0); $discount_html = $car->find('div[class=subtext vehicle_reference_element]', 0);
// Check if there is any discount info displayed // Check if there is any discount info displayed
@ -132,4 +151,18 @@ class AutoJMBridge extends BridgeAbstract
return $html; return $html;
} }
public function detectParameters($url)
{
$params = [];
$regex = '/^(https?:\/\/)?(www\.|)autojm.fr\/(recherche\?.*|recherche\/[0-9]{1,10}\?.*)$/m';
if (preg_match($regex, $url, $matches) > 0) {
$url = preg_replace('#(recherche|recherche/[0-9]{1,10})#', 'recherche', $matches[3]);
$params['url'] = $url;
$params['context'] = 'Afficher les offres de véhicules disponible sur la recheche AutoJM';
return $params;
}
}
} }