Skip to content

Commit

Permalink
[AutoJMBridge] Fix content extraction (RSS-Bridge#3649)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
sysadminstory authored Sep 5, 2023
1 parent 752098e commit 38b9573
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions bridges/AutoJMBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ class AutoJMBridge extends BridgeAbstract
'type' => 'text',
'required' => true,
'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 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()
{
return self::URI . 'favicon.ico';
Expand All @@ -35,6 +43,17 @@ public function getName()
}
}

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()
{
// Get the number of result for this search
Expand All @@ -52,7 +71,7 @@ public function collectData()
$data = json_decode($json);

$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
for ($page = 1; $page <= $total_pages && $page <= 10; $page++) {
Expand All @@ -66,8 +85,8 @@ public function collectData()
$image = $car->find('div[class=card-car__header__img]', 0)->find('img', 0)->src;
// Decode HTML attribute JSON data
$car_data = json_decode(html_entity_decode($car->{'data-layer'}));
$car_model = $car->{'data-title'} . ' ' . $car->{'data-suptitle'};
$availability = $car->find('div[class=card-car__modalites]', 0)->find('div[class=col]', 0)->plaintext;
$car_model = $car_data->title;
$availability = $car->find('div[class*=card-car__modalites]', 0)->find('div[class=col]', 0)->plaintext;
$warranty = $car->find('div[data-type=WarrantyCard]', 0)->plaintext;
$discount_html = $car->find('div[class=subtext vehicle_reference_element]', 0);
// Check if there is any discount info displayed
Expand Down Expand Up @@ -132,4 +151,18 @@ private function getResults(int $page)

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;
}
}
}

0 comments on commit 38b9573

Please sign in to comment.