summaryrefslogtreecommitdiff
path: root/share/xml2json
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-06-20 11:14:08 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-06-20 11:14:08 +0200
commit496391d23309aeabfbbf1f9088db3e508c548d6c (patch)
tree4f2f9d89508040356532294f5d933c0b2020a07a /share/xml2json
parent559160e3d32545fc5fd887a5f932005fe2a7d410 (diff)
identify and add missing stations from train routes
Diffstat (limited to 'share/xml2json')
-rwxr-xr-xshare/xml2json40
1 files changed, 31 insertions, 9 deletions
diff --git a/share/xml2json b/share/xml2json
index 951d578..84a1594 100755
--- a/share/xml2json
+++ b/share/xml2json
@@ -6,6 +6,7 @@ use 5.010;
use File::Slurp qw(read_file write_file);
use JSON;
+use List::Util qw(any);
use XML::LibXML;
my $json_str = read_file('stations.json');
@@ -15,6 +16,15 @@ my $stations = JSON->new->utf8->decode($json_str);
my $xml_str = read_file('stations.xml');
my $tree = XML::LibXML->load_xml( string => $xml_str );
+my @missing;
+
+if ( -e "missing.txt" ) {
+ for my $line ( read_file("missing.txt") ) {
+ chomp $line;
+ push( @missing, $line );
+ }
+}
+
for my $station ( $tree->findnodes('//station') ) {
my $name = $station->getAttribute('name');
my $eva = $station->getAttribute('eva');
@@ -44,25 +54,37 @@ for my $station ( $tree->findnodes('//station') ) {
$eva, $j_name, $name, $j_ds100, $ds100 );
last;
}
- elsif ( $j_name eq $name and $j_ds100 ne $ds100 and $is_db ) {
+ elsif ( $j_name eq $name
+ and $j_ds100 ne $ds100
+ and $is_db
+ and $ds100 !~ m{ ^ PQ }x )
+ {
printf( "%30s has been recoded: %8s -> %8s\n",
$name, $j_ds100, $ds100 );
last;
}
- elsif ( $j_name eq $name and $j_eva != $eva and $is_db ) {
+ elsif ( $j_name eq $name
+ and $j_eva != $eva
+ and $is_db
+ and $ds100 !~ m{ ^ PQ }x )
+ {
printf( "%30s has been recoded: %d -> %d\n", $name, $j_eva, $eva );
last;
}
}
- if (
- not $found
- and not( $ds100 =~ m{ ^ ( [OPXZ] | D[0-9] ) }x
- or $name =~ m{ ^ Bahnhof, }x
- or $name =~ m{ \(Gr\) $ }x )
- )
+ if ( not $found
+ and any { $_ eq $name } @missing )
{
- #say "missing $eva $ds100 \"$name\"";
+ say "missing $eva $ds100 \"$name\"";
+ push(
+ @{$stations},
+ {
+ name => $name,
+ ds100 => $ds100,
+ eva => $eva,
+ }
+ );
}
}