-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBinBinDataImporter.php
70 lines (51 loc) · 1.82 KB
/
BinBinDataImporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace App\Importers;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler;
class BinBinDataImporter extends DataImporter
{
private const LANGUAGE = "en";
protected Crawler $sections;
public function extract(): static
{
try {
$response = $this->client->get("https://www.binbin.tech/lokasyonlar");
$html = $response->getBody()->getContents();
} catch (GuzzleException) {
$this->createImportInfoDetails("400", self::getProviderName());
$this->stopExecution = true;
return $this;
}
$crawler = new Crawler($html);
$this->sections = $crawler->filter(".location-wrapper .cities-information .div-block-35");
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) {
$data = explode("|", $section->nodeValue);
$countryName = $this->translate(trim($data[1]), self::LANGUAGE);
if (trim($data[0]) === "Uşak") {
$cityName = "Usak";
} elseif (trim($data[0]) === "Murter") {
continue;
} else {
$cityName = $this->translate(trim($data[0]), "en");
}
$provider = $this->load($cityName, $countryName);
if ($provider !== "") {
$existingCityProviders[] = $provider;
}
}
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}
}