summaryrefslogtreecommitdiff
path: root/share/enhance
diff options
context:
space:
mode:
Diffstat (limited to 'share/enhance')
-rwxr-xr-xshare/enhance37
1 files changed, 37 insertions, 0 deletions
diff --git a/share/enhance b/share/enhance
new file mode 100755
index 0000000..25533c6
--- /dev/null
+++ b/share/enhance
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use File::Slurp qw(read_file write_file);
+use Travel::Status::DE::HAFAS;
+
+my $json_str = read_file('stations.json');
+my $stations = JSON->new->utf8->decode($json_str);
+@{$stations} = sort { $a->{name} cmp $b->{name} } @{$stations};
+
+my $ua = LWP::UserAgent->new();
+$ua->env_proxy;
+
+for my $station ( @{$stations} ) {
+ if ( not $station->{latlong} ) {
+ say "Requesting location for $station->{name} ...";
+ my $hafas = Travel::Status::DE::HAFAS->new(
+ locationSearch => $station->{name},
+ );
+ if (not scalar $hafas->results) {
+ say ' not found';
+ next;
+ }
+ my $result = ($hafas->results)[0];
+ if ($result->name ne $station->{name}) {
+ say ' name mismatch: got ' . $result->name;
+ next;
+ }
+ $station->{latlong} = [ $result->lat, $result->lon ];
+ }
+}
+
+my $json_out = JSON->new->utf8->canonical->pretty->encode($stations);
+write_file( 'stations.json', $json_out );