diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-01-28 23:00:23 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-01-28 23:00:23 +0100 |
commit | d0f6ffdbfee3b594adf58ce8a83d0564e2181639 (patch) | |
tree | e2d287505f0f4d74372f07b8abc3fc448910d7a0 /share/xml2meta | |
parent | 37c0aa5bb513da2cb6de7f673e97bc5192384e06 (diff) |
add "meta" dict (referenced / paired stations)
Diffstat (limited to 'share/xml2meta')
-rwxr-xr-x | share/xml2meta | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/share/xml2meta b/share/xml2meta new file mode 100755 index 0000000..ff8bb63 --- /dev/null +++ b/share/xml2meta @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +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'); +my %known_eva; +for my $station ( @{ JSON->new->utf8->decode($json_str) } ) { + $known_eva{ $station->{eva} } = 1; +} + +# Norddeich and Norddeich Mole are illegaly coupled in the backend (they are +# different stations with different departure times). Ignore their EVA IDs. +delete $known_eva{8007768}; +delete $known_eva{8004449}; + +my $xml_str = read_file('stations.xml'); +my $tree = XML::LibXML->load_xml( string => $xml_str ); + +my %meta; + +for my $station ( $tree->findnodes('//station') ) { + my $eva = $station->getAttribute('eva'); + my $meta = $station->getAttribute('meta'); + + if ( $known_eva{$eva} and $meta ) { + for my $ref ( split( qr{[|]}, $meta ) ) { + if ( $known_eva{$ref} ) { + push( @{ $meta{$eva} }, 0 + $ref ); + } + else { + say "Note: Ignoring $eva -> $ref (unknown)"; + } + } + } +} + +my $json_out = JSON->new->utf8->canonical->pretty->encode( {%meta} ); +write_file( 'meta.json', $json_out ); |