Skip to content

Commit f9a8efa

Browse files
committed
Add GoSharing provider
1 parent a9f38ad commit f9a8efa

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 GoSharingDataImporter extends DataImporter
12+
{
13+
protected Crawler $sections;
14+
15+
public function extract(): static
16+
{
17+
try {
18+
$response = $this->client->get("https://nl.go-sharing.com/en/locations/");
19+
$html = $response->getBody()->getContents();
20+
} catch (GuzzleException) {
21+
$this->createImportInfoDetails("400", self::getProviderName());
22+
23+
$this->stopExecution = true;
24+
25+
return $this;
26+
}
27+
28+
$crawler = new Crawler($html);
29+
$this->sections = $crawler->filter('section[id="show-cities"]');
30+
31+
if (count($this->sections) === 0) {
32+
$this->createImportInfoDetails("204", self::getProviderName());
33+
$this->stopExecution = true;
34+
}
35+
36+
return $this;
37+
}
38+
39+
public function transform(): void
40+
{
41+
if ($this->stopExecution) {
42+
return;
43+
}
44+
$existingCityProviders = [];
45+
$countryNames = [];
46+
47+
foreach ($this->sections as $section) {
48+
$sectionCrawler = new Crawler($section);
49+
$countries = $sectionCrawler->filter("h3");
50+
51+
foreach ($countries as $country) {
52+
$countryNames[] = $country->textContent;
53+
}
54+
55+
$countryCitiesRows = $sectionCrawler->filter('div[class="row location-row"]');
56+
$countryCitiesArray = [];
57+
58+
foreach ($countryCitiesRows as $countryCities) {
59+
$locationsCrawler = new Crawler($countryCities);
60+
$locations = $locationsCrawler->filter('div[class="location"]');
61+
62+
$citiesArray = [];
63+
64+
foreach ($locations as $location) {
65+
$cityCrawler = new Crawler($location);
66+
$cityName = $cityCrawler->text();
67+
68+
$activeServicesArray = [];
69+
$activeServices = $cityCrawler->filter('div[class="location__icons__icon active"]');
70+
71+
foreach ($activeServices as $activeService) {
72+
$serviceCrawler = new Crawler($activeService);
73+
$serviceType = $serviceCrawler->filter("img")->attr("alt");
74+
75+
if ($serviceType === "E-Scooter") {
76+
$activeServicesArray[] = ServicesEnum::Escooter;
77+
}
78+
79+
if ($serviceType === "E-Bike") {
80+
$activeServicesArray[] = ServicesEnum::Bike;
81+
}
82+
}
83+
84+
$citiesArray[] = [
85+
"cityName" => $cityName,
86+
"services" => $activeServicesArray,
87+
];
88+
}
89+
$countryCitiesArray[] = $citiesArray;
90+
}
91+
92+
$countryCount = count($countryNames);
93+
94+
for ($i = 0; $i < $countryCount; $i++) {
95+
$countryName = $countryNames[$i];
96+
$cities = $countryCitiesArray[$i];
97+
98+
foreach ($cities as $city) {
99+
$cityName = $city["cityName"];
100+
$services = $city["services"];
101+
102+
$provider = $this->load($cityName, $countryName, $lat = "", $long = "", $services);
103+
if ($provider !== "") {
104+
$existingCityProviders[] = $provider;
105+
}
106+
}
107+
}
108+
109+
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
110+
}
111+
}
112+
}

app/Jobs/GoSharingDataImporterJob.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\GoSharingDataImporter;
8+
9+
class GoSharingDataImporterJob extends DataImporterJob
10+
{
11+
public function handle(GoSharingDataImporter $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
@@ -11,6 +11,7 @@
1111
use App\Jobs\BitMobilityDataImporterJob;
1212
use App\Jobs\BoltDataImporterJob;
1313
use App\Jobs\DottDataImporterJob;
14+
use App\Jobs\GoSharingDataImporterJob;
1415
use App\Jobs\HopDataImporterJob;
1516
use App\Jobs\HoppDataImporterJob;
1617
use App\Jobs\HulajDataImporterJob;
@@ -68,6 +69,7 @@ public function run(string $whoRunsIt = "admin"): void
6869
new WheeMoveDataImporterJob($this->importInfoId),
6970
new HopDataImporterJob($this->importInfoId),
7071
new ZwingsDataImporterJob($this->importInfoId),
72+
new GoSharingDataImporterJob($this->importInfoId),
7173
new SixtDataImporterJob($this->importInfoId),
7274
])->finally(function (): void {
7375
ImportInfo::query()->where("id", $this->importInfoId)->update([

database/seeders/ProviderSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Importers\BitMobilityDataImporter;
1212
use App\Importers\BoltDataImporter;
1313
use App\Importers\DottDataImporter;
14+
use App\Importers\GoSharingDataImporter;
1415
use App\Importers\HopDataImporter;
1516
use App\Importers\HoppDataImporter;
1617
use App\Importers\HulajDataImporter;
@@ -44,6 +45,7 @@ public function run(): void
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"],
4647
["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"],
48+
["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"],
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"],
4951
["name" => HulajDataImporter::getProviderName(), "color" => "#d6213f", "url" => "https://hulaj.eu/", "android_url" => "https://play.google.com/store/apps/details?id=eu.hulaj&hl=pl&gl=US"],

public/providers/gosharing.png

3.11 KB
Loading

0 commit comments

Comments
 (0)