mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix import of postal codes. URL changed + names of keys
This commit is contained in:
parent
8fd6986c47
commit
8de37a9ef3
@ -23,7 +23,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||||||
*/
|
*/
|
||||||
class PostalCodeFRFromOpenData
|
class PostalCodeFRFromOpenData
|
||||||
{
|
{
|
||||||
private const CSV = 'https://datanova.laposte.fr/data-fair/api/v1/datasets/laposte-hexasmal/data-files/019HexaSmal.csv';
|
private const CSV = 'https://datanova.laposte.fr/data-fair/api/v1/datasets/laposte-hexasmal/metadata-attachments/base-officielle-codes-postaux.csv';
|
||||||
|
|
||||||
public function __construct(private readonly PostalCodeBaseImporter $baseImporter, private readonly HttpClientInterface $client, private readonly LoggerInterface $logger)
|
public function __construct(private readonly PostalCodeBaseImporter $baseImporter, private readonly HttpClientInterface $client, private readonly LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ class PostalCodeFRFromOpenData
|
|||||||
fseek($tmpfile, 0);
|
fseek($tmpfile, 0);
|
||||||
|
|
||||||
$csv = Reader::createFromStream($tmpfile);
|
$csv = Reader::createFromStream($tmpfile);
|
||||||
$csv->setDelimiter(';');
|
$csv->setDelimiter(',');
|
||||||
$csv->setHeaderOffset(0);
|
$csv->setHeaderOffset(0);
|
||||||
|
|
||||||
foreach ($csv as $offset => $record) {
|
foreach ($csv as $offset => $record) {
|
||||||
@ -65,23 +65,23 @@ class PostalCodeFRFromOpenData
|
|||||||
|
|
||||||
private function handleRecord(array $record): void
|
private function handleRecord(array $record): void
|
||||||
{
|
{
|
||||||
if ('' !== trim($record['coordonnees_geographiques'] ?? $record['coordonnees_gps'])) {
|
if ('' !== trim($record['_geopoint'])) {
|
||||||
[$lat, $lon] = array_map(static fn ($el) => (float) trim($el), explode(',', $record['coordonnees_geographiques'] ?? $record['coordonnees_gps']));
|
[$lat, $lon] = array_map(static fn ($el) => (float) trim($el), explode(',', $record['_geopoint']));
|
||||||
} else {
|
} else {
|
||||||
$lat = $lon = 0.0;
|
$lat = $lon = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ref = trim((string) $record['Code_commune_INSEE']);
|
$ref = trim((string) $record['code_commune_insee']);
|
||||||
|
|
||||||
if (str_starts_with($ref, '987')) {
|
if (str_starts_with($ref, '987')) {
|
||||||
// some differences in French Polynesia
|
// some differences in French Polynesia
|
||||||
$ref .= '.'.trim((string) $record['Libellé_d_acheminement']);
|
$ref .= '.'.trim((string) $record['libelle_d_acheminement']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->baseImporter->importCode(
|
$this->baseImporter->importCode(
|
||||||
'FR',
|
'FR',
|
||||||
trim((string) $record['Libellé_d_acheminement']),
|
trim((string) $record['libelle_d_acheminement']),
|
||||||
trim((string) $record['Code_postal']),
|
trim((string) $record['code_postal']),
|
||||||
$ref,
|
$ref,
|
||||||
'INSEE',
|
'INSEE',
|
||||||
$lat,
|
$lat,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user