Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#234 - Add Docomo provider #235

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/Importers/DocomoDataImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace App\Importers;

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

class DocomoDataImporter extends DataImporter
{
private const COUNTRY_NAME = "Japan";

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

public function extract(): static
{
try {
$response = $this->client->get("https://docomo-cycle.jp/?lang=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[class="show-all"]');

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

return $this;
}

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

$cities = $this->sections->filter('span[class="composite"]');

$cityNames = [];

foreach ($cities as $city) {
$cityNames[] = $city->textContent;
}

foreach ($cityNames as $cityName) {
$this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services);
}
}
}
15 changes: 15 additions & 0 deletions app/Jobs/DocomoDataImporterJob.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\DocomoDataImporter;

class DocomoDataImporterJob extends DataImporterJob
{
public function handle(DocomoDataImporter $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 @@ -10,6 +10,7 @@
use App\Jobs\BirdDataImporterJob;
use App\Jobs\BitMobilityDataImporterJob;
use App\Jobs\BoltDataImporterJob;
use App\Jobs\DocomoDataImporterJob;
use App\Jobs\DottDataImporterJob;
use App\Jobs\HopDataImporterJob;
use App\Jobs\HoppDataImporterJob;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function run(string $whoRunsIt = "admin"): void
new HoppDataImporterJob($this->importInfoId),
new LinkDataImporterJob($this->importInfoId),
new NeuronDataImporterJob($this->importInfoId),
new DocomoDataImporterJob($this->importInfoId),
new QuickDataImporterJob($this->importInfoId),
new RydeDataImporterJob($this->importInfoId),
new SpinDataImporterJob($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 @@ -10,6 +10,7 @@
use App\Importers\BirdDataImporter;
use App\Importers\BitMobilityDataImporter;
use App\Importers\BoltDataImporter;
use App\Importers\DocomoDataImporter;
use App\Importers\DottDataImporter;
use App\Importers\HopDataImporter;
use App\Importers\HoppDataImporter;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function run(): void
["name" => BirdDataImporter::getProviderName(), "color" => "#26ccf0", "url" => "https://www.bird.co/", "android_url" => "https://play.google.com/store/apps/details?id=co.bird.android", "ios_url" => "https://apps.apple.com/us/app/bird-be-free-enjoy-the-ride/id1260842311"],
["name" => BitMobilityDataImporter::getProviderName(), "color" => "#8da6e3", "url" => "https://bitmobility.it/en/", "android_url" => "https://play.google.com/store/apps/details?id=it.bitmobility.bit", "ios_url" => "https://apps.apple.com/it/app/bit/id1464155063"],
["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" => 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/docomo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading