-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDocomoDataImporter.php
61 lines (45 loc) · 1.51 KB
/
DocomoDataImporter.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
<?php
declare(strict_types=1);
namespace App\Importers;
use App\Enums\ServicesEnum;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler;
class DocomoDataImporter extends DataImporter
{
private const COUNTRY_NAME = "Japan";
protected Crawler $sections;
private array $services = [ServicesEnum::Bike];
public function extract(): static
{
try {
$response = $this->client->get("https://docomo-cycle.jp/?lang=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[class="show-all"]');
if (count($this->sections) === 0) {
$this->createImportInfoDetails("204", self::getProviderName());
$this->stopExecution = true;
}
return $this;
}
public function transform(): void
{
if ($this->stopExecution) {
return;
}
$existingCityProviders = [];
$cities = $this->sections->filter('span[class="composite"]');
$cityNames = [];
foreach ($cities as $city) {
$cityNames[] = $city->textContent;
}
foreach ($cityNames as $cityName) {
$this->load($cityName, self::COUNTRY_NAME, $lat = "", $long = "", $this->services);
}
}
}