Skip to content

Commit

Permalink
- add Felyx provider (#239)
Browse files Browse the repository at this point in the history
add felyx

Co-authored-by: Jakub Kermes <[email protected]>
  • Loading branch information
AleksandraKozubal and JakubKermes authored May 14, 2024
1 parent 8f72356 commit a74ad0f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
66 changes: 66 additions & 0 deletions app/Importers/FelyxDataImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace App\Importers;

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

class FelyxDataImporter extends DataImporter
{
protected Crawler $sections;
private array $services = [ServicesEnum::Emoped];

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

return $this;
}

$crawler = new Crawler($html);
$this->sections = $crawler->filter("p.styles_cityName__XdcTJ");

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) {
$cityName = $section->nodeValue;
$countryNode = $section->parentNode->parentNode->parentNode;

foreach ($countryNode->childNodes as $country) {
if ($country->nodeName === "h3") {
$countryName = trim($country->nodeValue);

$provider = $this->load($cityName, $countryName, $lat = "", $long = "", $this->services);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
}
}
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}
}
15 changes: 15 additions & 0 deletions app/Jobs/FelyxDataImporterJob.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\FelyxDataImporter;

class FelyxDataImporterJob extends DataImporterJob
{
public function handle(FelyxDataImporter $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 @@ -13,6 +13,7 @@
use App\Jobs\BoltDataImporterJob;
use App\Jobs\DocomoDataImporterJob;
use App\Jobs\DottDataImporterJob;
use App\Jobs\FelyxDataImporterJob;
use App\Jobs\GoSharingDataImporterJob;
use App\Jobs\HopDataImporterJob;
use App\Jobs\HoppDataImporterJob;
Expand Down Expand Up @@ -55,6 +56,7 @@ public function run(string $whoRunsIt = "admin"): void
new BitMobilityDataImporterJob($this->importInfoId),
new BoltDataImporterJob($this->importInfoId),
new DottDataImporterJob($this->importInfoId),
new FelyxDataImporterJob($this->importInfoId),
new HulajDataImporterJob($this->importInfoId),
new LimeDataImporterJob($this->importInfoId),
new HoppDataImporterJob($this->importInfoId),
Expand Down
2 changes: 2 additions & 0 deletions database/seeders/ProviderSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Importers\BoltDataImporter;
use App\Importers\DocomoDataImporter;
use App\Importers\DottDataImporter;
use App\Importers\FelyxDataImporter;
use App\Importers\GoSharingDataImporter;
use App\Importers\HopDataImporter;
use App\Importers\HoppDataImporter;
Expand Down Expand Up @@ -49,6 +50,7 @@ public function run(): void
["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"],
["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"],
["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"],
["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"],
["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"],
["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"],
["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"],
Expand Down
Binary file added public/providers/felyx.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 a74ad0f

Please sign in to comment.