summaryrefslogtreecommitdiff
path: root/share/json2json
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-12-22 14:38:41 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-12-22 14:38:41 +0100
commitffcda639681fb6e1e0f8ded6714ccb6d396e466e (patch)
treef150b5d0d875a728074d1e08f7b6938fd5fcecc2 /share/json2json
parentf403b2c124e2fe5fad9287bbc4f1d8d2cd12a5ee (diff)
json2json: prune invalid coordinates
Diffstat (limited to 'share/json2json')
-rwxr-xr-xshare/json2json18
1 files changed, 16 insertions, 2 deletions
diff --git a/share/json2json b/share/json2json
index ca67fe6..4a78e80 100755
--- a/share/json2json
+++ b/share/json2json
@@ -13,8 +13,9 @@ my $stations = JSON->new->utf8->decode($json_str);
my $have_duplicates = 0;
my @names = map { $_->{name} } @{$stations};
-my @ds100 = map { $_->{ds100} } sort { $a->{ds100} cmp $b->{ds100} } @{$stations};
-my @eva_ids = map { $_->{eva} } sort { $a->{eva} <=> $b->{eva} } @{$stations};
+my @ds100
+ = map { $_->{ds100} } sort { $a->{ds100} cmp $b->{ds100} } @{$stations};
+my @eva_ids = map { $_->{eva} } sort { $a->{eva} <=> $b->{eva} } @{$stations};
for my $i ( 1 .. $#names ) {
if ( $names[ $i - 1 ] eq $names[$i] ) {
@@ -40,5 +41,18 @@ if ($have_duplicates) {
say "Please remove duplicate entries before opening a pull request.";
}
+for my $station ( @{$stations} ) {
+ $station->{eva} = 0 + $station->{eva};
+ if ( $station->{latlong}
+ and $station->{latlong}[0] == 0
+ and $station->{latlong}[1] == 0 )
+ {
+ $station->{latlong} = undef;
+ }
+ elsif ( not exists $station->{latlong} ) {
+ $station->{latlong} = undef;
+ }
+}
+
my $json_out = JSON->new->utf8->canonical->pretty->encode($stations);
write_file( 'stations.json', $json_out );