-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sixt provider * update Sixt provider * fix Guzzle * update composer.json * update composer.lock * update phpunit.xml
- Loading branch information
1 parent
40335dc
commit fddc517
Showing
12 changed files
with
523 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class SixtDataImporter extends DataImporter | ||
{ | ||
protected Crawler $sections; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$headers = [ | ||
"User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", | ||
]; | ||
$response = $this->client->get("https://www.sixt.com/share/e-scooter/#/", ["headers" => $headers]); | ||
$html = $response->getBody()->getContents(); | ||
} catch (GuzzleException) { | ||
$this->createImportInfoDetails("400", self::getProviderName()); | ||
|
||
$this->stopExecution = true; | ||
|
||
return $this; | ||
} | ||
|
||
$crawler = new Crawler($html); | ||
|
||
$this->sections = $crawler->filter("div.item div.middle div.content ul"); | ||
|
||
if ($this->sections->count() === 0) { | ||
$this->createImportInfoDetails("204", self::getProviderName()); | ||
$this->stopExecution = true; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function transform(): void | ||
{ | ||
if ($this->stopExecution) { | ||
return; | ||
} | ||
|
||
$existingCityProviders = []; | ||
$countryName = ""; | ||
|
||
foreach ($this->sections as $section) { | ||
$node = $section->parentNode->parentNode->parentNode; | ||
|
||
foreach ($node->childNodes as $country) { | ||
if ($country instanceof \DOMElement) { | ||
$class = $country->getAttribute("class"); | ||
|
||
if ($class === "title") { | ||
$countryName = trim(preg_replace("/[^a-zA-Z ]/", "", $country->nodeValue)); | ||
} | ||
} | ||
} | ||
|
||
foreach ($section->childNodes as $city) { | ||
if ($city->nodeName === "li") { | ||
$cityName = trim(preg_replace('/\s+/', "", $city->nodeValue)); | ||
$provider = $this->load($cityName, $countryName); | ||
|
||
if ($provider !== "") { | ||
$existingCityProviders[] = $provider; | ||
} | ||
} | ||
} | ||
} | ||
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Importers\SixtDataImporter; | ||
|
||
class SixtDataImporterJob extends DataImporterJob | ||
{ | ||
public function handle(SixtDataImporter $importer): void | ||
{ | ||
$importer->setImportInfo($this->importInfoId)->extract()->transform(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.