Skip to content

Commit

Permalink
#155 - add wheemove provider (#165)
Browse files Browse the repository at this point in the history
* Added WheeMove provider

* Update readme.md

Added provider to the list

* Linted files

* Update app/Importers/WheeMoveDataImporter.php

Co-authored-by: vojcc <[email protected]>

* Update WheeMoveDataImporter.php

* Re added config/telescope.php

---------

Co-authored-by: vojcc <[email protected]>
  • Loading branch information
JakubKermes and vojcc authored Nov 8, 2023
1 parent fb2b2ed commit b0e89b9
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
67 changes: 67 additions & 0 deletions app/Importers/WheeMoveDataImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace App\Importers;

use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler;

class WheeMoveDataImporter extends DataImporter
{
private const COUNTRY_NAME = "Spain";

protected Crawler $sections;

public function extract(): static
{
try {
$response = $this->client->get("https://www.wheemove.com/");
$html = $response->getBody()->getContents();
} catch (GuzzleException) {
$this->createImportInfoDetails("400", self::getProviderName());
$this->stopExecution = true;
}

$crawler = new Crawler($html);

$this->sections = $crawler->filter('section[data-id="4b8f82b"], section[data-id="59def84"]');

if (count($this->sections) === 0) {
$this->createImportInfoDetails("204", self::getProviderName());

$this->stopExecution = true;
}

return $this;
}

public function transform(): void
{
$existingCityProviders = [];

if ($this->stopExecution) {
return;
}
$cityNames = [];

$firstSectionNames = $this->sections->first()->filter('span[class="elementor-icon-list-text"]');
$lastSectionNames = $this->sections->last()->filter('span[class="elementor-icon-list-text"]');

foreach ([$firstSectionNames, $lastSectionNames] as $sectionNames) {
foreach ($sectionNames as $name) {
$cityNames[] = $name->nodeValue;
}
}

foreach ($cityNames as $name) {
$provider = $this->load($name, self::COUNTRY_NAME);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}

$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}
}
15 changes: 15 additions & 0 deletions app/Jobs/WheeMoveDataImporterJob.php
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\WheeMoveDataImporter;

class WheeMoveDataImporterJob extends DataImporterJob
{
public function handle(WheeMoveDataImporter $importer): void
{
$importer->setImportInfo($this->importInfoId)->extract()->transform();
}
}
2 changes: 2 additions & 0 deletions app/Services/DataImporterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use App\Jobs\UrentDataImporterJob;
use App\Jobs\VeoDataImporterJob;
use App\Jobs\VoiDataImporterJob;
use App\Jobs\WheeMoveDataImporterJob;
use App\Jobs\WindDataImporterJob;
use App\Jobs\ZwingsDataImporterJob;
use App\Models\ImportInfo;
Expand Down Expand Up @@ -60,6 +61,7 @@ public function run(string $whoRunsIt = "admin"): void
new VoiDataImporterJob($this->importInfoId),
new VeoDataImporterJob($this->importInfoId),
new WindDataImporterJob($this->importInfoId),
new WheeMoveDataImporterJob($this->importInfoId),
new ZwingsDataImporterJob($this->importInfoId),
])->finally(function (): void {
ImportInfo::query()->where("id", $this->importInfoId)->update([
Expand Down
2 changes: 2 additions & 0 deletions database/seeders/ProviderSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use App\Importers\UrentDataImporter;
use App\Importers\VeoDataImporter;
use App\Importers\VoiDataImporter;
use App\Importers\WheeMoveDataImporter;
use App\Importers\WindDataImporter;
use App\Importers\ZwingsDataImporter;
use App\Models\Provider;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function run(): void
["name" => RydeDataImporter::getProviderName(), "color" => "#4dcb1f"],
["name" => VeoDataImporter::getProviderName(), "color" => "#000000"],
["name" => WindDataImporter::getProviderName(), "color" => "#fffa00"],
["name" => WheeMoveDataImporter::getProviderName(), "color" => "#31682d"],
];

foreach ($providers as $provider) {
Expand Down
Binary file added public/providers/wheemove.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
1. Urent
1. Veo
1. Voi
1. WheeMove
1. Zwings

### Local development
Expand Down

0 comments on commit b0e89b9

Please sign in to comment.