Skip to content

Commit 9862711

Browse files
committed
Add Docomo provider
1 parent a9f38ad commit 9862711

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

app/Importers/DocomoDataImporter.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 DocomoDataImporter extends DataImporter
12+
{
13+
private const COUNTRY_NAME = "Japan";
14+
15+
protected Crawler $sections;
16+
private array $services = [ServicesEnum::Bike];
17+
18+
public function extract(): static
19+
{
20+
try {
21+
$response = $this->client->get("https://docomo-cycle.jp/?lang=en");
22+
$html = $response->getBody()->getContents();
23+
} catch (GuzzleException) {
24+
$this->createImportInfoDetails("400", self::getProviderName());
25+
26+
$this->stopExecution = true;
27+
28+
return $this;
29+
}
30+
31+
$crawler = new Crawler($html);
32+
$this->sections = $crawler->filter('div[class="show-all"]');
33+
34+
if (count($this->sections) === 0) {
35+
$this->createImportInfoDetails("204", self::getProviderName());
36+
$this->stopExecution = true;
37+
}
38+
39+
return $this;
40+
}
41+
42+
public function transform(): void
43+
{
44+
if ($this->stopExecution) {
45+
return;
46+
}
47+
$existingCityProviders = [];
48+
49+
$cities = $this->sections->filter('span[class="composite"]');
50+
51+
$cityNames = [];
52+
53+
foreach ($cities as $city) {
54+
$cityNames[] = $city->textContent;
55+
}
56+
57+
foreach ($cityNames as $cityName) {
58+
$this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services);
59+
}
60+
}
61+
}

app/Jobs/DocomoDataImporterJob.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\DocomoDataImporter;
8+
9+
class DocomoDataImporterJob extends DataImporterJob
10+
{
11+
public function handle(DocomoDataImporter $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
@@ -10,6 +10,7 @@
1010
use App\Jobs\BirdDataImporterJob;
1111
use App\Jobs\BitMobilityDataImporterJob;
1212
use App\Jobs\BoltDataImporterJob;
13+
use App\Jobs\DocomoDataImporterJob;
1314
use App\Jobs\DottDataImporterJob;
1415
use App\Jobs\HopDataImporterJob;
1516
use App\Jobs\HoppDataImporterJob;
@@ -57,6 +58,7 @@ public function run(string $whoRunsIt = "admin"): void
5758
new HoppDataImporterJob($this->importInfoId),
5859
new LinkDataImporterJob($this->importInfoId),
5960
new NeuronDataImporterJob($this->importInfoId),
61+
new DocomoDataImporterJob($this->importInfoId),
6062
new QuickDataImporterJob($this->importInfoId),
6163
new RydeDataImporterJob($this->importInfoId),
6264
new SpinDataImporterJob($this->importInfoId),

database/seeders/ProviderSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Importers\BirdDataImporter;
1111
use App\Importers\BitMobilityDataImporter;
1212
use App\Importers\BoltDataImporter;
13+
use App\Importers\DocomoDataImporter;
1314
use App\Importers\DottDataImporter;
1415
use App\Importers\HopDataImporter;
1516
use App\Importers\HoppDataImporter;
@@ -43,6 +44,7 @@ public function run(): void
4344
["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"],
4445
["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"],
4546
["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"],
47+
["name" => DocomoDataImporter::getProviderName(), "color" => "#CA0029", "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"],
4648
["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"],
4749
["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"],
4850
["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/docomo.png

6.49 KB
Loading

0 commit comments

Comments
 (0)