From 20bca2f45e9025772f2fac3c98b5f0c7bfb23c11 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 26 May 2024 18:05:26 +0200 Subject: [PATCH] Ignore Versoix VD when updating data --- src/Console/UpdateZipcodeDatasetCommand.php | 27 +++++++++++++++++---- src/data/cities.json | 5 ---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Console/UpdateZipcodeDatasetCommand.php b/src/Console/UpdateZipcodeDatasetCommand.php index f08c9c0..6d2a077 100644 --- a/src/Console/UpdateZipcodeDatasetCommand.php +++ b/src/Console/UpdateZipcodeDatasetCommand.php @@ -75,7 +75,7 @@ protected function fetchDataset(): void // Open the destination file for writing in binary mode $fileHandler = fopen('/tmp/dataset.zip', 'wb'); - if (!$fileHandler) { + if (! $fileHandler) { throw new RuntimeException("Failed to open file for writing: '/tmp/dataset.zip'"); } @@ -100,7 +100,7 @@ protected function fetchDataset(): void foreach ($iterator as $file) { if ($file->isFile() && pathinfo($file->getPathname(), PATHINFO_EXTENSION) === 'csv') { $destinationFile = self::PATH_TO_CSV; - if (!rename($file->getPathname(), $destinationFile)) { + if (! rename($file->getPathname(), $destinationFile)) { // Handle potential errors during move operation throw new \Exception("Error moving file: " . $file->getPathname()); } @@ -130,10 +130,18 @@ protected function generateZipcodesFiles(TabularDataReader $records): void $data = []; foreach ($records as $zipcodeRecord) { + $city = $zipcodeRecord['Ortschaftsname']; + $zipcode = (int)$zipcodeRecord['PLZ']; + $canton = $zipcodeRecord['Kantonskürzel']; + + if ($this->shouldRecordBeIgnored($city, $zipcode, $canton)) { + continue; + } + $data[] = [ - 'city' => $zipcodeRecord['Ortschaftsname'], - 'zipcode' => (int) $zipcodeRecord['PLZ'], - 'canton' => $zipcodeRecord['Kantonskürzel'], + 'city' => $city, + 'zipcode' => $zipcode, + 'canton' => $canton, ]; } @@ -145,4 +153,13 @@ protected function cleanup(): void unlink('/tmp/dataset.zip'); unlink(self::PATH_TO_CSV); } + + protected function shouldRecordBeIgnored(string $city, int $zipcode, string $canton): bool + { + if ($zipcode === 1290 && $city === 'Versoix' && $canton === 'VD') { + return true; + } + + return false; + } } diff --git a/src/data/cities.json b/src/data/cities.json index 1b3740b..ae3c1cd 100644 --- a/src/data/cities.json +++ b/src/data/cities.json @@ -23604,11 +23604,6 @@ "zipcode": 1274, "canton": "VD" }, - { - "city": "Versoix", - "zipcode": 1290, - "canton": "VD" - }, { "city": "Mies", "zipcode": 1295,