diff options
author | Daniel Friesel <derf@finalrewind.org> | 2023-01-05 21:57:26 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2023-01-05 21:57:26 +0100 |
commit | 3074a8166ff91ab5e6a3cd3af293b9328eea923c (patch) | |
tree | 9fd8679e3bfb088b61a25e0d8e416a0f189938e7 /share | |
parent | 616419c4ae55998b4048d18cf574f04cfb81bdea (diff) |
xml2json: optionally only add re-appeared stations if they have departures
Diffstat (limited to 'share')
-rwxr-xr-x | share/xml2json | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/share/xml2json b/share/xml2json index e30d48b..54a86be 100755 --- a/share/xml2json +++ b/share/xml2json @@ -10,7 +10,12 @@ use List::Util qw(any); use XML::LibXML; # old / new / renamed / reappeared / missing -my $mode = shift; +my $mode = shift; +my $extra = shift // q{}; + +if ( $extra eq 'if-active' ) { + use Travel::Status::DE::IRIS; +} my $json = JSON->new->utf8; my $json_str = read_file('stations.json'); @@ -109,6 +114,21 @@ sub delete_old_station { } @{$old_stations}; } +sub has_departures { + my ($eva) = @_; + + my $status = Travel::Status::DE::IRIS->new( + station => $eva, + lookbehind => 120, + lookahead => 240 + ); + + if ( $status->results ) { + return 1; + } + return; +} + # TODO falls ein eintrag aus old_stations im XML auftaucht sollte er aus old_stations raus und wieder in stations rein if ( -e 'missing.txt' ) { @@ -205,15 +225,22 @@ for my $station ( $tree->findnodes('//station') ) { { printf( "%30s has re-appeared as %s %d\n", $name, $ds100, $eva ); if ( not $mode or $mode eq 'reappeared' ) { - if ( ref($old) eq 'ARRAY' ) { - for my $o ( @{$old} ) { - delete_old_station( $o->{name}, $o->{ds100}, $o->{eva} ); + if ( $extra ne 'if-active' or has_departures($eva) ) { + if ( ref($old) eq 'ARRAY' ) { + for my $o ( @{$old} ) { + delete_old_station( $o->{name}, $o->{ds100}, + $o->{eva} ); + } } + else { + delete_old_station( $old->{name}, $old->{ds100}, + $old->{eva} ); + } + add_station( $name, $ds100, $eva ); } - else { - delete_old_station( $old->{name}, $old->{ds100}, $old->{eva} ); + if ( $extra eq 'if-active' ) { + sleep(1); } - add_station( $name, $ds100, $eva ); } } |