Skip to content

Commit

Permalink
Add Baqme provider
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed May 13, 2024
1 parent a9f38ad commit 0cccd3a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
67 changes: 67 additions & 0 deletions app/Importers/BaqmeDataImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace App\Importers;

use App\Enums\ServicesEnum;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler;

class BaqmeDataImporter extends DataImporter
{
private const COUNTRY_NAME = "Netherlands";

protected Crawler $sections;
private array $services = [ServicesEnum::Cargo];

public function extract(): static
{
try {
$response = $this->client->get("https://www.baqme.com/en/");
$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.coming");

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

return $this;
}

public function transform(): void
{
if ($this->stopExecution) {
return;
}
$existingCityProviders = [];

foreach ($this->sections as $section) {
$city = new Crawler($section);
$cityData = $city->filter("b")->html();
$cityArray = explode("<br>", $cityData);

if (count($cityArray) > 1 && $cityArray[1] === "Coming soon") {
continue;
}
$cityName = $cityArray[0];
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services);

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

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

class BaqmeDataImporterJob extends DataImporterJob
{
public function handle(BaqmeDataImporter $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 @@ -4,6 +4,7 @@

namespace App\Services;

use App\Jobs\BaqmeDataImporterJob;
use App\Jobs\BeamDataImporterJob;
use App\Jobs\BerylDataImporterJob;
use App\Jobs\BinBinDataImporterJob;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function run(string $whoRunsIt = "admin"): void
new WindDataImporterJob($this->importInfoId),
new WheeMoveDataImporterJob($this->importInfoId),
new HopDataImporterJob($this->importInfoId),
new BaqmeDataImporterJob($this->importInfoId),
new ZwingsDataImporterJob($this->importInfoId),
new SixtDataImporterJob($this->importInfoId),
])->finally(function (): void {
Expand Down
2 changes: 2 additions & 0 deletions database/seeders/ProviderSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Database\Seeders;

use App\Importers\BaqmeDataImporter;
use App\Importers\BeamDataImporter;
use App\Importers\BerylDataImporter;
use App\Importers\BinBinDataImporter;
Expand Down Expand Up @@ -37,6 +38,7 @@ class ProviderSeeder extends Seeder
public function run(): void
{
$providers = [
["name" => BaqmeDataImporter::getProviderName(), "color" => "#50E3C2", "url" => "https://baqme.com/", "android_url" => "https://play.google.com/store/apps/details?id=com.baqme.android", "ios_url" => "https://apps.apple.com/us/app/baqme/id1538722828"],
["name" => BeamDataImporter::getProviderName(), "color" => "#7347ff", "url" => "https://www.ridebeam.com/", "android_url" => "https://play.google.com/store/apps/details?id=com.escooterapp&pli=1", "ios_url" => "https://apps.apple.com/app/id1427114484"],
["name" => BerylDataImporter::getProviderName(), "color" => "#00e3c2", "url" => "https://beryl.cc/", "android_url" => "https://play.google.com/store/apps/details?id=cc.beryl.basis", "ios_url" => "https://apps.apple.com/app/id1386768364"],
["name" => BinBinDataImporter::getProviderName(), "color" => "#3dbcc8", "url" => "https://www.binbin.tech/", "android_url" => "https://play.google.com/store/apps/details?id=com.BINBIN&hl=en_US", "ios_url" => "https://apps.apple.com/us/app/binbin-scooters/id1483635924"],
Expand Down
Binary file added public/providers/baqme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0cccd3a

Please sign in to comment.