summaryrefslogtreecommitdiff
path: root/share/xml2json
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-13 14:57:24 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-13 14:57:24 +0100
commit4b52f63fcc68806071cd16ca5ee6c80bba2ce92f (patch)
tree71ba64ea478ca0a5dcefa80377105a4e45a85382 /share/xml2json
parentc7cf0166e5ab27a1b3ab9d7915f2caa5a19a2414 (diff)
xml2json: automatically remove stations no longer available in HAFAS
Diffstat (limited to 'share/xml2json')
-rwxr-xr-xshare/xml2json43
1 files changed, 39 insertions, 4 deletions
diff --git a/share/xml2json b/share/xml2json
index 1004d0c..951d578 100755
--- a/share/xml2json
+++ b/share/xml2json
@@ -19,6 +19,7 @@ for my $station ( $tree->findnodes('//station') ) {
my $name = $station->getAttribute('name');
my $eva = $station->getAttribute('eva');
my $ds100 = $station->getAttribute('ds100');
+ my $is_db = $station->getAttribute('db') eq 'true';
my $found = 0;
@@ -43,23 +44,57 @@ for my $station ( $tree->findnodes('//station') ) {
$eva, $j_name, $name, $j_ds100, $ds100 );
last;
}
- elsif ( $j_name eq $name and $j_ds100 ne $ds100 ) {
+ elsif ( $j_name eq $name and $j_ds100 ne $ds100 and $is_db ) {
printf( "%30s has been recoded: %8s -> %8s\n",
$name, $j_ds100, $ds100 );
last;
}
- elsif ( $j_name eq $name and $j_eva != $eva ) {
+ elsif ( $j_name eq $name and $j_eva != $eva and $is_db ) {
printf( "%30s has been recoded: %d -> %d\n", $name, $j_eva, $eva );
last;
}
}
- if ( not $found
- and not( $ds100 =~ m{ ^ [OPXZ] }x or $name =~ m{ ^ Bahnhof, }x ) )
+ if (
+ not $found
+ and not( $ds100 =~ m{ ^ ( [OPXZ] | D[0-9] ) }x
+ or $name =~ m{ ^ Bahnhof, }x
+ or $name =~ m{ \(Gr\) $ }x )
+ )
{
#say "missing $eva $ds100 \"$name\"";
}
}
+my @to_delete;
+
+for my $i ( 0 .. $#{$stations} ) {
+ my $j_station = $stations->[$i];
+ my $j_name = $j_station->{name};
+ my $j_ds100 = $j_station->{ds100};
+ my $j_eva = $j_station->{eva};
+
+ my $found = 0;
+
+ for my $station ( $tree->findnodes('//station') ) {
+ my $name = $station->getAttribute('name');
+ my $eva = $station->getAttribute('eva');
+ my $ds100 = $station->getAttribute('ds100');
+ my $is_db = $station->getAttribute('db') eq 'true';
+ if ( $name eq $j_name or $eva == $j_eva ) {
+ $found = 1;
+ }
+ }
+
+ if ( not $found ) {
+ say "station no longer exists: $j_eva $j_ds100 \"$j_name\"";
+ unshift( @to_delete, $i );
+ }
+}
+
+for my $i (@to_delete) {
+ splice( @{$stations}, $i, 1 );
+}
+
my $json_out = JSON->new->utf8->canonical->pretty->encode($stations);
write_file( 'stations.json', $json_out );