-
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.
Merge branch '#146-adding-login-via-social-media' of https://github.c…
…om/blumilksoftware/escooters into #146-adding-login-via-social-media
- Loading branch information
Showing
39 changed files
with
1,292 additions
and
748 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
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
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
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class HopDataImporter extends DataImporter | ||
{ | ||
protected Crawler $sections; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$response = $this->client->get("https://hop.bike/en/location-list.html"); | ||
$html = $response->getBody()->getContents(); | ||
} catch (GuzzleException) { | ||
$this->createImportInfoDetails("400", self::getProviderName()); | ||
$this->stopExecution = true; | ||
} | ||
|
||
$crawler = new Crawler($html); | ||
|
||
$this->sections = $crawler->filter('section[class="location-list"]'); | ||
|
||
if (count($this->sections) === 0) { | ||
$this->createImportInfoDetails("204", self::getProviderName()); | ||
|
||
$this->stopExecution = true; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function transform(): void | ||
{ | ||
$existingCityProviders = []; | ||
|
||
if ($this->stopExecution) { | ||
return; | ||
} | ||
|
||
$locations = []; | ||
|
||
$countryList = $this->sections->filter('div[class="location-list-body-main-title"]'); | ||
$citySectionList = $this->sections->filter('div[class="location-list-body-main-list"]'); | ||
|
||
foreach ($countryList as $index => $country) { | ||
$citySection = $citySectionList->eq($index); | ||
$cities = $citySection->filter('li[class="location-list-body-main-list-title text-body-xl"]'); | ||
|
||
foreach ($cities as $city) { | ||
$locations[] = [ | ||
"country" => $country->textContent, | ||
"city" => $city->textContent, | ||
]; | ||
} | ||
} | ||
|
||
foreach ($locations as $location) { | ||
$location["country"] = preg_replace('/\s+/', "", $location["country"]); | ||
$location["city"] = preg_replace('/\s+/', "", $location["city"]); | ||
|
||
$provider = $this->load($location["city"], $location["country"]); | ||
|
||
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class HoppDataImporter extends DataImporter | ||
{ | ||
protected Crawler $sections; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$response = $this->client->get("https://hopp.bike/locations"); | ||
$html = $response->getBody()->getContents(); | ||
} catch (GuzzleException) { | ||
$this->createImportInfoDetails("400", self::getProviderName()); | ||
$this->stopExecution = true; | ||
} | ||
|
||
$crawler = new Crawler($html); | ||
|
||
$this->sections = $crawler->filter('section[class="sc-3ad02d05-0 eZsxrq"]'); | ||
|
||
if (count($this->sections) === 0) { | ||
$this->createImportInfoDetails("204", self::getProviderName()); | ||
|
||
$this->stopExecution = true; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function transform(): void | ||
{ | ||
$existingCityProviders = []; | ||
|
||
if ($this->stopExecution) { | ||
return; | ||
} | ||
|
||
$locations = []; | ||
|
||
$countryList = $this->sections->filter('h1[class="sc-188713c8-0 kHXWNs"]'); | ||
$citySectionList = $this->sections->filter('div[class="sc-3ad02d05-0 gqLRPj"]'); | ||
|
||
foreach ($countryList as $index => $country) { | ||
$citySection = $citySectionList->eq($index); | ||
$cities = $citySection->filter('p[class="sc-188713c8-0 bGGtqk"]'); | ||
|
||
foreach ($cities as $city) { | ||
$locations[] = [ | ||
"country" => $country->textContent, | ||
"city" => $city->textContent, | ||
]; | ||
} | ||
} | ||
|
||
foreach ($locations as $location) { | ||
$location["country"] = preg_replace('/\s+/', "", $location["country"]); | ||
$location["city"] = preg_replace('/\s+/', "", $location["city"]); | ||
|
||
$provider = $this->load($location["city"], $location["country"]); | ||
|
||
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
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,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Importers; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class SixtDataImporter extends DataImporter | ||
{ | ||
protected Crawler $sections; | ||
|
||
public function extract(): static | ||
{ | ||
try { | ||
$headers = [ | ||
"User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", | ||
]; | ||
$response = $this->client->get("https://www.sixt.com/share/e-scooter/#/", ["headers" => $headers]); | ||
$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.item div.middle div.content ul"); | ||
|
||
if ($this->sections->count() === 0) { | ||
$this->createImportInfoDetails("204", self::getProviderName()); | ||
$this->stopExecution = true; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function transform(): void | ||
{ | ||
if ($this->stopExecution) { | ||
return; | ||
} | ||
|
||
$existingCityProviders = []; | ||
$countryName = ""; | ||
|
||
foreach ($this->sections as $section) { | ||
$node = $section->parentNode->parentNode->parentNode; | ||
|
||
foreach ($node->childNodes as $country) { | ||
if ($country instanceof \DOMElement) { | ||
$class = $country->getAttribute("class"); | ||
|
||
if ($class === "title") { | ||
$countryName = trim(preg_replace("/[^a-zA-Z ]/", "", $country->nodeValue)); | ||
} | ||
} | ||
} | ||
|
||
foreach ($section->childNodes as $city) { | ||
if ($city->nodeName === "li") { | ||
$cityName = trim(preg_replace('/\s+/', "", $city->nodeValue)); | ||
$provider = $this->load($cityName, $countryName); | ||
|
||
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
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\HopDataImporter; | ||
|
||
class HopDataImporterJob extends DataImporterJob | ||
{ | ||
public function handle(HopDataImporter $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
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\HoppDataImporter; | ||
|
||
class HoppDataImporterJob extends DataImporterJob | ||
{ | ||
public function handle(HoppDataImporter $importer): void | ||
{ | ||
$importer->setImportInfo($this->importInfoId)->extract()->transform(); | ||
} | ||
} |
Oops, something went wrong.