-
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.
add felyx Co-authored-by: Jakub Kermes <[email protected]>
- Loading branch information
1 parent
8f72356
commit a74ad0f
Showing
5 changed files
with
85 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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use App\Enums\ServicesEnum; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class FelyxDataImporter extends DataImporter | ||
{ | ||
protected Crawler $sections; | ||
private array $services = [ServicesEnum::Emoped]; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$response = $this->client->get("https://felyx.com/products/our-locations/"); | ||
$html = $response->getBody()->getContents(); | ||
} catch (GuzzleException) { | ||
$this->createImportInfoDetails("400", self::getProviderName()); | ||
$this->stopExecution = true; | ||
|
||
return $this; | ||
} | ||
|
||
$crawler = new Crawler($html); | ||
$this->sections = $crawler->filter("p.styles_cityName__XdcTJ"); | ||
|
||
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) { | ||
$cityName = $section->nodeValue; | ||
$countryNode = $section->parentNode->parentNode->parentNode; | ||
|
||
foreach ($countryNode->childNodes as $country) { | ||
if ($country->nodeName === "h3") { | ||
$countryName = trim($country->nodeValue); | ||
|
||
$provider = $this->load($cityName, $countryName, $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\FelyxDataImporter; | ||
|
||
class FelyxDataImporterJob extends DataImporterJob | ||
{ | ||
public function handle(FelyxDataImporter $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.