summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rwxr-xr-xshare/find-missing72
-rwxr-xr-xshare/xml2json40
2 files changed, 90 insertions, 22 deletions
diff --git a/share/find-missing b/share/find-missing
index 909c203..e69a7a1 100755
--- a/share/find-missing
+++ b/share/find-missing
@@ -1,13 +1,59 @@
-#!/bin/zsh
-
-: > missing.txt
-
-./xml2json | fgrep missing | shuf | while read m eva x ; do
- if [[ $x != *,* ]] && db-iris -x $eva &> /dev/null; then
- echo "\n$m $eva $x"
- echo $m $eva $x >> missing.txt
- else
- echo -n .
- fi
- sleep .2
-done
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use Cache::File;
+use List::Util qw(uniq);
+use Travel::Status::DE::IRIS;
+use Travel::Status::DE::IRIS::Stations;
+
+my ($station) = @ARGV;
+
+my $cache_path = $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache";
+my $schedule_cache_path = "${cache_path}/db-iris-schedule";
+my $realtime_cache_path = "${cache_path}/db-iris-realtime";
+my ( $schedule_cache, $realtime_cache );
+
+eval {
+ use Cache::File;
+ $schedule_cache = Cache::File->new(
+ cache_root => $schedule_cache_path,
+ default_expires => '6 hours',
+ lock_level => Cache::File::LOCK_LOCAL(),
+ );
+ $realtime_cache = Cache::File->new(
+ cache_root => $realtime_cache_path,
+ default_expires => '180 seconds',
+ lock_level => Cache::File::LOCK_LOCAL(),
+ );
+};
+if ($@) {
+ $schedule_cache = undef;
+ $realtime_cache = undef;
+}
+
+my $status = Travel::Status::DE::IRIS->new(
+ station => $station,
+ main_cache => $schedule_cache,
+ realtime_cache => $realtime_cache,
+ with_related => 1,
+);
+
+my @missing;
+
+for my $result ( $status->results ) {
+ for my $name ( $result->route_pre, $result->route_post ) {
+ my @matches
+ = Travel::Status::DE::IRIS::Stations::get_station_by_name($name);
+ if ( @matches != 1 ) {
+ push( @missing, $name );
+ }
+ elsif ( $matches[0][1] ne $name ) {
+ push( @missing, $name );
+ }
+ }
+}
+
+say join( "\n", uniq @missing );
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,
+ }
+ );
}
}