Skip to content

Commit a74ad0f

Browse files
- add Felyx provider (#239)
add felyx Co-authored-by: Jakub Kermes <114694305+JakubKermes@users.noreply.github.com>
1 parent 8f72356 commit a74ad0f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

app/Importers/FelyxDataImporter.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 FelyxDataImporter extends DataImporter
12+
{
13+
protected Crawler $sections;
14+
private array $services = [ServicesEnum::Emoped];
15+
16+
public function extract(): static
17+
{
18+
try {
19+
$response = $this->client->get("https://felyx.com/products/our-locations/");
20+
$html = $response->getBody()->getContents();
21+
} catch (GuzzleException) {
22+
$this->createImportInfoDetails("400", self::getProviderName());
23+
$this->stopExecution = true;
24+
25+
return $this;
26+
}
27+
28+
$crawler = new Crawler($html);
29+
$this->sections = $crawler->filter("p.styles_cityName__XdcTJ");
30+
31+
if (count($this->sections) === 0) {
32+
$this->createImportInfoDetails("204", self::getProviderName());
33+
34+
$this->stopExecution = true;
35+
}
36+
37+
return $this;
38+
}
39+
40+
public function transform(): void
41+
{
42+
if ($this->stopExecution) {
43+
return;
44+
}
45+
46+
$existingCityProviders = [];
47+
48+
foreach ($this->sections as $section) {
49+
$cityName = $section->nodeValue;
50+
$countryNode = $section->parentNode->parentNode->parentNode;
51+
52+
foreach ($countryNode->childNodes as $country) {
53+
if ($country->nodeName === "h3") {
54+
$countryName = trim($country->nodeValue);
55+
56+
$provider = $this->load($cityName, $countryName, $lat = "", $long = "", $this->services);
57+
58+
if ($provider !== "") {
59+
$existingCityProviders[] = $provider;
60+
}
61+
}
62+
}
63+
}
64+
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
65+
}
66+
}

app/Jobs/FelyxDataImporterJob.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\FelyxDataImporter;
8+
9+
class FelyxDataImporterJob extends DataImporterJob
10+
{
11+
public function handle(FelyxDataImporter $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
@@ -13,6 +13,7 @@
1313
use App\Jobs\BoltDataImporterJob;
1414
use App\Jobs\DocomoDataImporterJob;
1515
use App\Jobs\DottDataImporterJob;
16+
use App\Jobs\FelyxDataImporterJob;
1617
use App\Jobs\GoSharingDataImporterJob;
1718
use App\Jobs\HopDataImporterJob;
1819
use App\Jobs\HoppDataImporterJob;
@@ -55,6 +56,7 @@ public function run(string $whoRunsIt = "admin"): void
5556
new BitMobilityDataImporterJob($this->importInfoId),
5657
new BoltDataImporterJob($this->importInfoId),
5758
new DottDataImporterJob($this->importInfoId),
59+
new FelyxDataImporterJob($this->importInfoId),
5860
new HulajDataImporterJob($this->importInfoId),
5961
new LimeDataImporterJob($this->importInfoId),
6062
new HoppDataImporterJob($this->importInfoId),

database/seeders/ProviderSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use App\Importers\BoltDataImporter;
1414
use App\Importers\DocomoDataImporter;
1515
use App\Importers\DottDataImporter;
16+
use App\Importers\FelyxDataImporter;
1617
use App\Importers\GoSharingDataImporter;
1718
use App\Importers\HopDataImporter;
1819
use App\Importers\HoppDataImporter;
@@ -49,6 +50,7 @@ public function run(): void
4950
["name" => BoltDataImporter::getProviderName(), "color" => "#24f0a0", "url" => "https://bolt.eu/pl-pl/scooters/", "android_url" => "https://play.google.com/store/apps/details?id=ee.mtakso.client&hl=pl&gl=US", "ios_url" => "https://apps.apple.com/pl/app/bolt-przejazdy-hulajnogi/id675033630?l=pl"],
5051
["name" => DocomoDataImporter::getProviderName(), "color" => "#faf9f6", "url" => "https://docomo-cycle.jp/?lang=en", "android_url" => "https://play.google.com/store/apps/details?id=jp.docomo_cycle.bikeshare", "ios_url" => "https://apps.apple.com/jp/app/id1475196715"],
5152
["name" => DottDataImporter::getProviderName(), "color" => "#f5c604", "url" => "https://ridedott.com/", "android_url" => "https://play.google.com/store/apps/details?id=com.ridedott.rider&pli=1", "ios_url" => "https://apps.apple.com/us/app/dott-unlock-your-city/id1440301673"],
53+
["name" => FelyxDataImporter::getProviderName(), "color" => "#044a27", "url" => "https://felyx.com/", "android_url" => "https://play.google.com/store/apps/details?id=com.felyx.android", "ios_url" => "https://apps.apple.com/us/app/felyx/id1250107307"],
5254
["name" => GoSharingDataImporter::getProviderName(), "color" => "#81BB28", "url" => "https://nl.go-sharing.com/en/locations/", "android_url" => "https://play.google.com/store/apps/details?id=nl.gosharing.gourban.app&hl=pl&gl=US", "ios_url" => "https://apps.apple.com/pl/app/go-sharing/id1477465763?l=pl"],
5355
["name" => HopDataImporter::getProviderName(), "color" => "#ea1821", "url" => "https://hop.bike/en/", "android_url" => "https://play.google.com/store/apps/details?id=com.hoplagit.rider&hl=pl&gl=US", "ios_url" => "https://apps.apple.com/pl/app/hop-enjoy-the-city/id1487640704?l=pl"],
5456
["name" => HoppDataImporter::getProviderName(), "color" => "#1ce5be", "url" => "https://hopp.bike/", "android_url" => "https://play.google.com/store/apps/details?id=bike.hopp", "ios_url" => "https://apps.apple.com/us/app/hopp-scooters/id1471324642?ls=1"],

public/providers/felyx.png

2.32 KB
Loading

0 commit comments

Comments
 (0)