Find PanneauPocket city id from page URL (#3825)

Co-authored-by: Guillaume Lacasa <git@adhess.net>
This commit is contained in:
Guillaume Lacasa 2023-12-11 17:38:39 +01:00 committed by GitHub
parent 4a398a5b14
commit a3b064f4ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 2 deletions

View File

@ -12,6 +12,12 @@ class PanneauPocketBridge extends BridgeAbstract
'name' => 'Choisir une ville',
'type' => 'list',
'values' => self::CITIES,
],
'cityName' => [
'name' => 'Ville',
],
'cityId' => [
'name' => 'Identifiant',
]
]
];
@ -113,8 +119,14 @@ class PanneauPocketBridge extends BridgeAbstract
public function collectData()
{
$matchedCity = array_search($this->getInput('cities'), self::CITIES);
$city = strtolower($this->getInput('cities') . '-' . $matchedCity);
$cityId = $this->getInput('cityId');
if ($cityId != null) {
$cityName = $this->getInput('cityName');
$city = strtolower($cityId . '-' . $cityName);
} else {
$matchedCity = array_search($this->getInput('cities'), self::CITIES);
$city = strtolower($this->getInput('cities') . '-' . $matchedCity);
}
$url = sprintf('https://app.panneaupocket.com/ville/%s', urlencode($city));
$html = getSimpleHTMLDOM($url);
@ -136,6 +148,18 @@ class PanneauPocketBridge extends BridgeAbstract
}
}
public function detectParameters($url)
{
$params = [];
$regex = '/\/ville\/(\d+)-([a-z0-9-]+)/';
if (preg_match($regex, $url, $matches)) {
$params['cityId'] = $matches[1];
$params['cityName'] = $matches[2];
return $params;
}
return null;
}
/**
* Produce self::CITIES array
*/