-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9f38ad
commit 0cccd3a
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use App\Enums\ServicesEnum; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class BaqmeDataImporter extends DataImporter | ||
{ | ||
private const COUNTRY_NAME = "Netherlands"; | ||
|
||
protected Crawler $sections; | ||
private array $services = [ServicesEnum::Cargo]; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$response = $this->client->get("https://www.baqme.com/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.coming"); | ||
|
||
if (count($this->sections) === 0) { | ||
$this->createImportInfoDetails("204", self::getProviderName()); | ||
$this->stopExecution = true; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function transform(): void | ||
{ | ||
if ($this->stopExecution) { | ||
return; | ||
} | ||
$existingCityProviders = []; | ||
|
||
foreach ($this->sections as $section) { | ||
$city = new Crawler($section); | ||
$cityData = $city->filter("b")->html(); | ||
$cityArray = explode("<br>", $cityData); | ||
|
||
if (count($cityArray) > 1 && $cityArray[1] === "Coming soon") { | ||
continue; | ||
} | ||
$cityName = $cityArray[0]; | ||
$provider = $this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services); | ||
|
||
if ($provider) { | ||
$existingCityProviders[] = $provider; | ||
} | ||
} | ||
|
||
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\BaqmeDataImporter; | ||
|
||
class BaqmeDataImporterJob extends DataImporterJob | ||
{ | ||
public function handle(BaqmeDataImporter $importer): void | ||
{ | ||
$importer->setImportInfo($this->importInfoId)->extract()->transform(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.