2018-09-13 12:05:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AutoJMBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'AutoJM';
|
2019-04-04 23:39:39 +03:00
|
|
|
const URI = 'https://www.autojm.fr/';
|
2018-09-13 12:05:07 +03:00
|
|
|
const DESCRIPTION = 'Suivre les offres de véhicules proposés par AutoJM en fonction des critères de filtrages';
|
|
|
|
const MAINTAINER = 'sysadminstory';
|
|
|
|
const PARAMETERS = [
|
2022-01-02 00:15:13 +03:00
|
|
|
'Afficher les offres de véhicules disponible sur la recheche AutoJM' => [
|
2018-09-13 12:05:07 +03:00
|
|
|
'url' => [
|
2022-01-02 00:15:13 +03:00
|
|
|
'name' => 'URL de la page de recherche',
|
2018-09-13 12:05:07 +03:00
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'URL d\'une recherche avec filtre de véhicules sans le http://www.autojm.fr/',
|
2022-01-02 00:15:13 +03:00
|
|
|
'exampleValue' => 'recherche?brands[]=peugeot&ranges[]=peugeot-nouvelle-308-2021-5p'
|
2019-04-04 23:39:39 +03:00
|
|
|
],
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-09-13 12:05:07 +03:00
|
|
|
];
|
|
|
|
const CACHE_TIMEOUT = 3600;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
2019-04-04 23:39:39 +03:00
|
|
|
return self::URI . 'favicon.ico';
|
2018-10-26 19:07:34 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-04-20 23:22:06 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
2022-01-02 00:15:13 +03:00
|
|
|
case 'Afficher les offres de véhicules disponible sur la recheche AutoJM':
|
|
|
|
return 'AutoJM | Recherche de véhicules';
|
2019-04-20 23:22:06 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getName();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2018-09-13 12:05:07 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-01-02 00:15:13 +03:00
|
|
|
// Get the number of result for this search
|
|
|
|
$search_url = self::URI . $this->getInput('url') . '&open=energy&onlyFilters=false';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:05:04 +03:00
|
|
|
// Set the header 'X-Requested-With' like the website does it
|
2019-04-04 23:39:39 +03:00
|
|
|
$header = [
|
2020-05-17 21:05:04 +03:00
|
|
|
'X-Requested-With: XMLHttpRequest'
|
2019-04-04 23:39:39 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-04-04 23:39:39 +03:00
|
|
|
// Get the JSON content of the form
|
2022-01-02 00:15:13 +03:00
|
|
|
$json = getContents($search_url, $header);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-04-04 23:39:39 +03:00
|
|
|
// Extract the HTML content from the JSON result
|
|
|
|
$data = json_decode($json);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
$nb_results = $data->nbResults;
|
|
|
|
$total_pages = ceil($nb_results / 15);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
// Limit the number of page to analyse to 10
|
|
|
|
for ($page = 1; $page <= $total_pages && $page <= 10; $page++) {
|
|
|
|
// Get the result the next page
|
|
|
|
$html = $this->getResults($page);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
// Go through every car of the search
|
|
|
|
$list = $html->find('div[class*=card-car card-car--listing]');
|
|
|
|
foreach ($list as $car) {
|
|
|
|
// Get the info about the car offer
|
|
|
|
$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;
|
|
|
|
$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
|
|
|
|
if ($discount_html != null) {
|
|
|
|
$reference_price_value = $discount_html->find('span[data-cfg=vehicle__reference_price]', 0)->plaintext;
|
|
|
|
$discount_percent_value = $discount_html->find('span[data-cfg=vehicle__discount_percent]', 0)->plaintext;
|
|
|
|
$reference_price = '<li>Prix de référence : <s>' . $reference_price_value . '</s></li>';
|
|
|
|
$discount_percent = '<li>Réduction : ' . $discount_percent_value . ' %</li>';
|
|
|
|
} else {
|
|
|
|
$reference_price = '';
|
|
|
|
$discount_percent = '';
|
|
|
|
}
|
|
|
|
$price = $car_data->price;
|
|
|
|
$kilometer = $car->find('span[data-cfg=vehicle__kilometer]', 0)->plaintext;
|
|
|
|
$energy = $car->find('span[data-cfg=vehicle__energy__label]', 0)->plaintext;
|
|
|
|
$power = $car->find('span[data-cfg=vehicle__tax_horse_power]', 0)->plaintext;
|
|
|
|
$seats = $car->find('span[data-cfg=vehicle__seats]', 0)->plaintext;
|
|
|
|
$doors = $car->find('span[data-cfg=vehicle__door__label]', 0)->plaintext;
|
|
|
|
$transmission = $car->find('span[data-cfg=vehicle__transmission]', 0)->plaintext;
|
|
|
|
$loa_html = $car->find('span[data-cfg=vehicle__loa]', 0);
|
|
|
|
// Check if any LOA price is displayed
|
|
|
|
if ($loa_html != null) {
|
|
|
|
$loa_value = $car->find('span[data-cfg=vehicle__loa]', 0)->plaintext;
|
|
|
|
$loa = '<li>LOA : à partir de ' . $loa_value . ' / mois </li>';
|
|
|
|
} else {
|
|
|
|
$loa = '';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
// Construct the new item
|
|
|
|
$item = [];
|
|
|
|
$item['title'] = $car_model;
|
|
|
|
$item['content'] = '<p><img style="vertical-align:middle ; padding: 10px" src="' . $image . '" />'
|
|
|
|
. $car_model . '</p>';
|
|
|
|
$item['content'] .= '<ul><li>Disponibilité : ' . $availability . '</li>';
|
|
|
|
$item['content'] .= '<li>Prix : ' . $price . ' €</li>';
|
|
|
|
$item['content'] .= $reference_price;
|
|
|
|
$item['content'] .= $loa;
|
|
|
|
$item['content'] .= $discount_percent;
|
|
|
|
$item['content'] .= '<li>Garantie : ' . $warranty . '</li>';
|
|
|
|
$item['content'] .= '<li>Kilométrage : ' . $kilometer . ' km</li>';
|
|
|
|
$item['content'] .= '<li>Energie : ' . $energy . '</li>';
|
|
|
|
$item['content'] .= '<li>Puissance: ' . $power . ' CV Fiscaux</li>';
|
|
|
|
$item['content'] .= '<li>Nombre de Places : ' . $seats . ' place(s)</li>';
|
|
|
|
$item['content'] .= '<li>Nombre de portes : ' . $doors . '</li>';
|
|
|
|
$item['content'] .= '<li>Boite de vitesse : ' . $transmission . '</li></ul>';
|
|
|
|
$item['uri'] = $car_data->{'uri'};
|
|
|
|
$item['uid'] = hash('md5', $item['content']);
|
|
|
|
$this->items[] = $item;
|
2018-09-13 12:05:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
private function getResults(int $page)
|
|
|
|
{
|
|
|
|
$user_input = $this->getInput('url');
|
|
|
|
$search_data = preg_replace('#(recherche|recherche/[0-9]{1,10})\?#', 'recherche/' . $page . '?', $user_input);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
$search_url = self::URI . $search_data . '&open=energy&onlyFilters=false';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
// Get the HTML content of the page
|
|
|
|
$html = getSimpleHTMLDOMCached($search_url);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 00:15:13 +03:00
|
|
|
return $html;
|
|
|
|
}
|
2018-09-13 12:05:07 +03:00
|
|
|
}
|