summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-11-18 18:46:34 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-11-18 18:46:34 +0100
commit77e2ce9c74f1892dcc0f93f75e33c77f5f06856f (patch)
tree43fea70091af85de35d7c815a3e943b0f9c7392e /share
parentc890c1d086a01a8cd2e33282315429fc23c80c6e (diff)
csv2json: Check for duplicate entries
Diffstat (limited to 'share')
-rwxr-xr-xshare/csv2json29
1 files changed, 29 insertions, 0 deletions
diff --git a/share/csv2json b/share/csv2json
index 1cfd3ee..9e6340c 100755
--- a/share/csv2json
+++ b/share/csv2json
@@ -48,5 +48,34 @@ for my $line (@csv_lines) {
@stations = sort { $a->{name} cmp $b->{name} } @stations;
+my $have_duplicates = 0;
+my @names = map { $_->{name} } @stations;
+my @ds100 = map { $_->{ds100} } @stations;
+my @uic_ids = map { $_->{uic} } @stations;
+
+for my $i ( 1 .. $#names ) {
+ if ( $names[ $i - 1 ] eq $names[$i] ) {
+ say "Duplicate station name: $names[$i]";
+ $have_duplicates = 1;
+ }
+}
+for my $i ( 1 .. $#ds100 ) {
+ if ( $ds100[ $i - 1 ] eq $ds100[$i] ) {
+ say "Duplicate DS100 code: $ds100[$i]";
+ $have_duplicates = 1;
+ }
+}
+for my $i ( 1 .. $#uic_ids ) {
+ if ( $uic_ids[ $i - 1 ] == $uic_ids[$i] ) {
+ say "Duplicate UIC ID: $uic_ids[$i]";
+ $have_duplicates = 1;
+ }
+}
+
+if ($have_duplicates) {
+ say "Data has NOT been converted to stations.json";
+ say "Please remove duplicates and run $0 again";
+}
+
my $json_out = JSON->new->utf8->canonical->pretty->encode( [@stations] );
write_file( 'stations.json', $json_out );