4
4
5
5
namespace App \Importers ;
6
6
7
- use App \Enums \ServicesEnum ;
8
7
use GuzzleHttp \Exception \GuzzleException ;
9
8
use Symfony \Component \DomCrawler \Crawler ;
10
9
@@ -28,7 +27,7 @@ public function extract(): static
28
27
}
29
28
30
29
$ crawler = new Crawler ($ html );
31
- $ this ->sections = $ crawler ->filter (' div[class="view-content col-xs-12 col-sm-12"] ' )-> filter ( " div[class='views-row'] " );
30
+ $ this ->sections = $ crawler ->filter (" div > section > div .inner " );
32
31
33
32
if (count ($ this ->sections ) === 0 ) {
34
33
$ this ->createImportInfoDetails ("204 " , self ::getProviderName ());
@@ -47,69 +46,58 @@ public function transform(): void
47
46
$ existingCityProviders = [];
48
47
49
48
foreach ($ this ->sections as $ section ) {
50
- $ crawler = new Crawler ($ section );
51
- $ cityName = $ crawler ->filter ("h3 " )->text ();
52
- $ this ->data [] = $ cityName ;
53
-
54
- $ servicesNodes = $ crawler ->filter ('div[class="field--label"] ' );
55
- $ availableServices = [];
56
-
57
- foreach ($ servicesNodes as $ serviceNode ) {
58
- $ serviceCrawler = new Crawler ($ serviceNode );
59
- $ service = $ serviceCrawler ->text ();
60
-
61
- if ($ service === "e-Bikes " ) {
62
- $ availableServices [] = ServicesEnum::Bike;
63
- }
64
-
65
- if ($ service === "e-Scooters " ) {
66
- $ availableServices [] = ServicesEnum::Escooter;
67
- }
68
-
69
- if ($ service === "Cargo " ) {
70
- $ availableServices [] = ServicesEnum::Cargo;
71
- }
72
- }
73
-
74
- if ($ cityName === "Bournemouth Christchurch Poole " ) {
75
- $ arrayOfCityNames = explode (" " , $ cityName );
76
-
77
- foreach ($ arrayOfCityNames as $ cityName ) {
78
- $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME , $ lat = "" , $ long = "" , $ availableServices );
79
-
80
- if ($ provider !== "" ) {
81
- $ existingCityProviders [] = $ provider ;
49
+ foreach ($ section ->childNodes as $ node ) {
50
+ if ($ node ->nodeName === "div " ) {
51
+ foreach ($ node ->childNodes as $ city ) {
52
+ if ($ city ->nodeName === "h3 " ) {
53
+ $ cityName = $ city ->nodeValue ;
54
+ }
55
+
56
+ $ eScootersFound = false ;
57
+
58
+ if ($ city ->nodeValue === "e-Scooters " ) {
59
+ $ eScootersFound = true ;
60
+ }
61
+
62
+ if ($ eScootersFound ) {
63
+ $ cityName = str_replace (["E-scooters " , "and " , ", " ], "" , $ cityName );
64
+ $ cityName = trim ($ cityName );
65
+
66
+ if ($ cityName === "Bournemouth Christchurch Poole " ) {
67
+ $ arrayOfCityNames = explode (" " , $ cityName );
68
+
69
+ foreach ($ arrayOfCityNames as $ cityName ) {
70
+ $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME );
71
+
72
+ if ($ provider !== "" ) {
73
+ $ existingCityProviders [] = $ provider ;
74
+ }
75
+ }
76
+ } elseif ($ cityName === "West Midlands " ) {
77
+ $ cityName = "Birmingham " ;
78
+ }
79
+
80
+ if ($ cityName === "Isle of Wight " ) {
81
+ $ arrayOfCityNames = ["Cowes " , "East Cowes " , "Newport " , "Ryde " , "Sandown " , "Shanklin " ];
82
+
83
+ foreach ($ arrayOfCityNames as $ cityName ) {
84
+ $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME );
85
+
86
+ if ($ provider !== "" ) {
87
+ $ existingCityProviders [] = $ provider ;
88
+ }
89
+ }
90
+ }
91
+ $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME );
92
+
93
+ if ($ provider !== "" ) {
94
+ $ existingCityProviders [] = $ provider ;
95
+ }
96
+ }
82
97
}
83
98
}
84
- } elseif ($ cityName === "West Midlands " ) {
85
- $ cityName = "Birmingham " ;
86
- } elseif ($ cityName === "Isle of Wight " ) {
87
- $ arrayOfCityNames = ["Cowes " , "East Cowes " , "Newport " , "Ryde " , "Sandown " , "Shanklin " ];
88
-
89
- foreach ($ arrayOfCityNames as $ cityName ) {
90
- $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME , $ lat = "" , $ long = "" , $ availableServices );
91
-
92
- if ($ provider !== "" ) {
93
- $ existingCityProviders [] = $ provider ;
94
- }
95
- }
96
- }
97
- $ provider = $ this ->load ($ cityName , self ::COUNTRY_NAME , $ lat = "" , $ long = "" , $ availableServices );
98
-
99
- if ($ provider !== "" ) {
100
- $ existingCityProviders [] = $ provider ;
101
99
}
102
100
}
103
-
104
101
$ this ->deleteMissingProviders (self ::getProviderName (), $ existingCityProviders );
105
102
}
106
-
107
- public function test ()
108
- {
109
- $ this ->extract ()->transform ();
110
- $ sectionCount = count ($ this ->sections );
111
- $ this ->data [] = ["sections " => "$ sectionCount " ];
112
-
113
- return $ this ->data ;
114
- }
115
103
}
0 commit comments