Skip to content

Commit

Permalink
Ignore Versoix VD when updating data
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzweifel committed May 26, 2024
1 parent ff91b81 commit 20bca2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 22 additions & 5 deletions src/Console/UpdateZipcodeDatasetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
}

Expand All @@ -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());
}
Expand Down Expand Up @@ -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,
];
}

Expand All @@ -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;
}
}
5 changes: 0 additions & 5 deletions src/data/cities.json
Original file line number Diff line number Diff line change
Expand Up @@ -23604,11 +23604,6 @@
"zipcode": 1274,
"canton": "VD"
},
{
"city": "Versoix",
"zipcode": 1290,
"canton": "VD"
},
{
"city": "Mies",
"zipcode": 1295,
Expand Down

0 comments on commit 20bca2f

Please sign in to comment.