Skip to content

Commit 7bba16b

Browse files
committed
Update BerylDataImporter.php
1 parent a9f38ad commit 7bba16b

File tree

1 file changed

+49
-61
lines changed

1 file changed

+49
-61
lines changed

app/Importers/BerylDataImporter.php

+49-61
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace App\Importers;
66

7-
use App\Enums\ServicesEnum;
87
use GuzzleHttp\Exception\GuzzleException;
98
use Symfony\Component\DomCrawler\Crawler;
109

@@ -28,7 +27,7 @@ public function extract(): static
2827
}
2928

3029
$crawler = new Crawler($html);
31-
$this->sections = $crawler->filter('div[class="view-content col-xs-12 col-sm-12"]')->filter("div[class='views-row']");
30+
$this->sections = $crawler->filter("div > section > div .inner");
3231

3332
if (count($this->sections) === 0) {
3433
$this->createImportInfoDetails("204", self::getProviderName());
@@ -47,69 +46,58 @@ public function transform(): void
4746
$existingCityProviders = [];
4847

4948
foreach ($this->sections as $section) {
50-
$crawler = new Crawler($section);
51-
$cityName = $crawler->filter("h3")->text();
52-
$this->data[] = $cityName;
53-
54-
$servicesNodes = $crawler->filter('div[class="field--label"]');
55-
$availableServices = [];
56-
57-
foreach ($servicesNodes as $serviceNode) {
58-
$serviceCrawler = new Crawler($serviceNode);
59-
$service = $serviceCrawler->text();
60-
61-
if ($service === "e-Bikes") {
62-
$availableServices[] = ServicesEnum::Bike;
63-
}
64-
65-
if ($service === "e-Scooters") {
66-
$availableServices[] = ServicesEnum::Escooter;
67-
}
68-
69-
if ($service === "Cargo") {
70-
$availableServices[] = ServicesEnum::Cargo;
71-
}
72-
}
73-
74-
if ($cityName === "Bournemouth Christchurch Poole") {
75-
$arrayOfCityNames = explode(" ", $cityName);
76-
77-
foreach ($arrayOfCityNames as $cityName) {
78-
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);
79-
80-
if ($provider !== "") {
81-
$existingCityProviders[] = $provider;
49+
foreach ($section->childNodes as $node) {
50+
if ($node->nodeName === "div") {
51+
foreach ($node->childNodes as $city) {
52+
if ($city->nodeName === "h3") {
53+
$cityName = $city->nodeValue;
54+
}
55+
56+
$eScootersFound = false;
57+
58+
if ($city->nodeValue === "e-Scooters") {
59+
$eScootersFound = true;
60+
}
61+
62+
if ($eScootersFound) {
63+
$cityName = str_replace(["E-scooters", "and ", ","], "", $cityName);
64+
$cityName = trim($cityName);
65+
66+
if ($cityName === "Bournemouth Christchurch Poole") {
67+
$arrayOfCityNames = explode(" ", $cityName);
68+
69+
foreach ($arrayOfCityNames as $cityName) {
70+
$provider = $this->load($cityName, self::COUNTRY_NAME);
71+
72+
if ($provider !== "") {
73+
$existingCityProviders[] = $provider;
74+
}
75+
}
76+
} elseif ($cityName === "West Midlands") {
77+
$cityName = "Birmingham";
78+
}
79+
80+
if ($cityName === "Isle of Wight") {
81+
$arrayOfCityNames = ["Cowes", "East Cowes", "Newport", "Ryde", "Sandown", "Shanklin"];
82+
83+
foreach ($arrayOfCityNames as $cityName) {
84+
$provider = $this->load($cityName, self::COUNTRY_NAME);
85+
86+
if ($provider !== "") {
87+
$existingCityProviders[] = $provider;
88+
}
89+
}
90+
}
91+
$provider = $this->load($cityName, self::COUNTRY_NAME);
92+
93+
if ($provider !== "") {
94+
$existingCityProviders[] = $provider;
95+
}
96+
}
8297
}
8398
}
84-
} elseif ($cityName === "West Midlands") {
85-
$cityName = "Birmingham";
86-
} elseif ($cityName === "Isle of Wight") {
87-
$arrayOfCityNames = ["Cowes", "East Cowes", "Newport", "Ryde", "Sandown", "Shanklin"];
88-
89-
foreach ($arrayOfCityNames as $cityName) {
90-
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);
91-
92-
if ($provider !== "") {
93-
$existingCityProviders[] = $provider;
94-
}
95-
}
96-
}
97-
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);
98-
99-
if ($provider !== "") {
100-
$existingCityProviders[] = $provider;
10199
}
102100
}
103-
104101
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
105102
}
106-
107-
public function test()
108-
{
109-
$this->extract()->transform();
110-
$sectionCount = count($this->sections);
111-
$this->data[] = ["sections" => "$sectionCount"];
112-
113-
return $this->data;
114-
}
115103
}

0 commit comments

Comments
 (0)