summaryrefslogtreecommitdiff
path: root/share/enhance
diff options
context:
space:
mode:
Diffstat (limited to 'share/enhance')
-rwxr-xr-xshare/enhance26
1 files changed, 11 insertions, 15 deletions
diff --git a/share/enhance b/share/enhance
index 5fe683f..545ac65 100755
--- a/share/enhance
+++ b/share/enhance
@@ -5,8 +5,7 @@ use warnings;
use 5.010;
use File::Slurp qw(read_file write_file);
-use JSON;
-use LWP::UserAgent;
+use Travel::Status::DE::HAFAS;
my $json_str = read_file('stations.json');
my $stations = JSON->new->utf8->decode($json_str);
@@ -18,20 +17,17 @@ $ua->env_proxy;
for my $station ( @{$stations} ) {
if ( not $station->{latlong} ) {
say "Requesting location for $station->{name} ...";
- my $res = $ua->get(
- 'https://marudor.de/api/station/v1/station/' . $station->{eva} );
- if ( $res->is_error ) {
- say ' marudor.de returned error ' . $res->status_line;
+ my $hafas = Travel::Status::DE::HAFAS->new(
+ locationSearch => $station->{name},
+ );
+ if ( not scalar $hafas->results ) {
+ say ' not found';
+ next;
}
- else {
- my $content = $res->decoded_content;
- my $json = JSON->new->utf8->decode($content);
- if ( $json and $json->{location} and $json->{location}{latitude} ) {
- $station->{latlong} = [ $json->{location}{latitude},
- $json->{location}{longitude} ];
- }
- else {
- say ' marudor.de has no location';
+ for my $result ( $hafas->results ) {
+ if ( $result->name eq $station->{name} ) {
+ $station->{latlong} = [ $result->lat, $result->lon ];
+ last;
}
}
}