Loading share/enhance +11 −17 Original line number Original line Diff line number Diff line Loading @@ -5,8 +5,7 @@ use warnings; use 5.010; use 5.010; use File::Slurp qw(read_file write_file); use File::Slurp qw(read_file write_file); use JSON; use Travel::Status::DE::HAFAS; use LWP::UserAgent; my $json_str = read_file('stations.json'); my $json_str = read_file('stations.json'); my $stations = JSON->new->utf8->decode($json_str); my $stations = JSON->new->utf8->decode($json_str); Loading @@ -18,24 +17,19 @@ $ua->env_proxy; for my $station ( @{$stations} ) { for my $station ( @{$stations} ) { if ( not $station->{latlong} ) { if ( not $station->{latlong} ) { say "Requesting location for $station->{name} ..."; say "Requesting location for $station->{name} ..."; my $res = $ua->get( my $hafas = Travel::Status::DE::HAFAS->new( sprintf( 'https://v6.db.transport.rest/stops/%07d', locationSearch => $station->{name}, $station->{eva} ) ); ); if ( $res->is_error ) { if (not scalar $hafas->results) { say ' transport.rest returned error ' . $res->status_line; say ' not found'; next; } } else { my $result = ($hafas->results)[0]; my $content = $res->decoded_content; if ($result->name ne $station->{name}) { my $json = JSON->new->utf8->decode($content); say ' name mismatch: got ' . $result->name; if ( $json and $json->{location} and $json->{location}{latitude} ) { next; $station->{latlong} = [ $json->{location}{latitude}, $json->{location}{longitude} ]; } else { say ' transport.rest has no location'; } } } $station->{latlong} = [ $result->lat, $result->lon ]; } } } } Loading Loading
share/enhance +11 −17 Original line number Original line Diff line number Diff line Loading @@ -5,8 +5,7 @@ use warnings; use 5.010; use 5.010; use File::Slurp qw(read_file write_file); use File::Slurp qw(read_file write_file); use JSON; use Travel::Status::DE::HAFAS; use LWP::UserAgent; my $json_str = read_file('stations.json'); my $json_str = read_file('stations.json'); my $stations = JSON->new->utf8->decode($json_str); my $stations = JSON->new->utf8->decode($json_str); Loading @@ -18,24 +17,19 @@ $ua->env_proxy; for my $station ( @{$stations} ) { for my $station ( @{$stations} ) { if ( not $station->{latlong} ) { if ( not $station->{latlong} ) { say "Requesting location for $station->{name} ..."; say "Requesting location for $station->{name} ..."; my $res = $ua->get( my $hafas = Travel::Status::DE::HAFAS->new( sprintf( 'https://v6.db.transport.rest/stops/%07d', locationSearch => $station->{name}, $station->{eva} ) ); ); if ( $res->is_error ) { if (not scalar $hafas->results) { say ' transport.rest returned error ' . $res->status_line; say ' not found'; next; } } else { my $result = ($hafas->results)[0]; my $content = $res->decoded_content; if ($result->name ne $station->{name}) { my $json = JSON->new->utf8->decode($content); say ' name mismatch: got ' . $result->name; if ( $json and $json->{location} and $json->{location}{latitude} ) { next; $station->{latlong} = [ $json->{location}{latitude}, $json->{location}{longitude} ]; } else { say ' transport.rest has no location'; } } } $station->{latlong} = [ $result->lat, $result->lon ]; } } } } Loading