Skip to content

Commit 293e2b6

Browse files
#232 - Add Baqme provider (#233)
* Add Baqme provider * cr change --------- Co-authored-by: Aleksandra Kozubal <aleksandra.kozubal@studenci.collegiumwitelona.pl>
1 parent eda4154 commit 293e2b6

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

app/Importers/BaqmeDataImporter.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Importers;
6+
7+
use App\Enums\ServicesEnum;
8+
use GuzzleHttp\Exception\GuzzleException;
9+
use Symfony\Component\DomCrawler\Crawler;
10+
11+
class BaqmeDataImporter extends DataImporter
12+
{
13+
private const COUNTRY_NAME = "Netherlands";
14+
15+
protected Crawler $sections;
16+
private array $services = [ServicesEnum::Cargo];
17+
18+
public function extract(): static
19+
{
20+
try {
21+
$response = $this->client->get("https://www.baqme.com/en/");
22+
$html = $response->getBody()->getContents();
23+
} catch (GuzzleException) {
24+
$this->createImportInfoDetails("400", self::getProviderName());
25+
$this->stopExecution = true;
26+
27+
return $this;
28+
}
29+
30+
$crawler = new Crawler($html);
31+
$this->sections = $crawler->filter("div.coming");
32+
33+
if (count($this->sections) === 0) {
34+
$this->createImportInfoDetails("204", self::getProviderName());
35+
$this->stopExecution = true;
36+
}
37+
38+
return $this;
39+
}
40+
41+
public function transform(): void
42+
{
43+
if ($this->stopExecution) {
44+
return;
45+
}
46+
$existingCityProviders = [];
47+
48+
foreach ($this->sections as $section) {
49+
$city = new Crawler($section);
50+
$cityData = $city->filter("b")->html();
51+
$cityArray = explode("<br>", $cityData);
52+
53+
if (count($cityArray) > 1 && $cityArray[1] === "Coming soon") {
54+
continue;
55+
}
56+
$cityName = $cityArray[0];
57+
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services);
58+
59+
if ($provider) {
60+
$existingCityProviders[] = $provider;
61+
}
62+
}
63+
64+
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
65+
}
66+
}

app/Jobs/BaqmeDataImporterJob.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Jobs;
6+
7+
use App\Importers\BaqmeDataImporter;
8+
9+
class BaqmeDataImporterJob extends DataImporterJob
10+
{
11+
public function handle(BaqmeDataImporter $importer): void
12+
{
13+
$importer->setImportInfo($this->importInfoId)->extract()->transform();
14+
}
15+
}

app/Services/DataImporterService.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Services;
66

7+
use App\Jobs\BaqmeDataImporterJob;
78
use App\Jobs\BeamDataImporterJob;
89
use App\Jobs\BerylDataImporterJob;
910
use App\Jobs\BinBinDataImporterJob;
@@ -67,6 +68,7 @@ public function run(string $whoRunsIt = "admin"): void
6768
new WindDataImporterJob($this->importInfoId),
6869
new WheeMoveDataImporterJob($this->importInfoId),
6970
new HopDataImporterJob($this->importInfoId),
71+
new BaqmeDataImporterJob($this->importInfoId),
7072
new ZwingsDataImporterJob($this->importInfoId),
7173
new SixtDataImporterJob($this->importInfoId),
7274
])->finally(function (): void {

database/seeders/ProviderSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Database\Seeders;
66

7+
use App\Importers\BaqmeDataImporter;
78
use App\Importers\BeamDataImporter;
89
use App\Importers\BerylDataImporter;
910
use App\Importers\BinBinDataImporter;
@@ -37,6 +38,7 @@ class ProviderSeeder extends Seeder
3738
public function run(): void
3839
{
3940
$providers = [
41+
["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"],
4042
["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"],
4143
["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"],
4244
["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"],

public/providers/baqme.png

2.96 KB
Loading

0 commit comments

Comments
 (0)