Skip to content

Commit

Permalink
Find PanneauPocket city id from page URL (RSS-Bridge#3825)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lacasa <[email protected]>
  • Loading branch information
glacasa and Guillaume Lacasa authored Dec 11, 2023
1 parent 4a398a5 commit a3b064f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions bridges/PanneauPocketBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class PanneauPocketBridge extends BridgeAbstract
'name' => 'Choisir une ville',
'type' => 'list',
'values' => self::CITIES,
],
'cityName' => [
'name' => 'Ville',
],
'cityId' => [
'name' => 'Identifiant',
]
]
];
Expand Down Expand Up @@ -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);
Expand All @@ -136,6 +148,18 @@ public function collectData()
}
}

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
*/
Expand Down

0 comments on commit a3b064f

Please sign in to comment.