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

#230 - Update Beryl provider to handle multiple services #231

Closed
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
110 changes: 49 additions & 61 deletions app/Importers/BerylDataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Importers;

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

Expand All @@ -28,7 +27,7 @@ public function extract(): static
}

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

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

foreach ($this->sections as $section) {
$crawler = new Crawler($section);
$cityName = $crawler->filter("h3")->text();
$this->data[] = $cityName;

$servicesNodes = $crawler->filter('div[class="field--label"]');
$availableServices = [];

foreach ($servicesNodes as $serviceNode) {
$serviceCrawler = new Crawler($serviceNode);
$service = $serviceCrawler->text();

if ($service === "e-Bikes") {
$availableServices[] = ServicesEnum::Bike;
}

if ($service === "e-Scooters") {
$availableServices[] = ServicesEnum::Escooter;
}

if ($service === "Cargo") {
$availableServices[] = ServicesEnum::Cargo;
}
}

if ($cityName === "Bournemouth Christchurch Poole") {
$arrayOfCityNames = explode(" ", $cityName);

foreach ($arrayOfCityNames as $cityName) {
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);

if ($provider !== "") {
$existingCityProviders[] = $provider;
foreach ($section->childNodes as $node) {
if ($node->nodeName === "div") {
foreach ($node->childNodes as $city) {
if ($city->nodeName === "h3") {
$cityName = $city->nodeValue;
}

$eScootersFound = false;

if ($city->nodeValue === "e-Scooters") {
$eScootersFound = true;
}

if ($eScootersFound) {
$cityName = str_replace(["E-scooters", "and ", ","], "", $cityName);
$cityName = trim($cityName);

if ($cityName === "Bournemouth Christchurch Poole") {
$arrayOfCityNames = explode(" ", $cityName);

foreach ($arrayOfCityNames as $cityName) {
$provider = $this->load($cityName, self::COUNTRY_NAME);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
} elseif ($cityName === "West Midlands") {
$cityName = "Birmingham";
}

if ($cityName === "Isle of Wight") {
$arrayOfCityNames = ["Cowes", "East Cowes", "Newport", "Ryde", "Sandown", "Shanklin"];

foreach ($arrayOfCityNames as $cityName) {
$provider = $this->load($cityName, self::COUNTRY_NAME);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
}
$provider = $this->load($cityName, self::COUNTRY_NAME);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
}
}
} elseif ($cityName === "West Midlands") {
$cityName = "Birmingham";
} elseif ($cityName === "Isle of Wight") {
$arrayOfCityNames = ["Cowes", "East Cowes", "Newport", "Ryde", "Sandown", "Shanklin"];

foreach ($arrayOfCityNames as $cityName) {
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
}
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $availableServices);

if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}

$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}

public function test()
{
$this->extract()->transform();
$sectionCount = count($this->sections);
$this->data[] = ["sections" => "$sectionCount"];

return $this->data;
}
}
Loading