Skip to content
GitLab
Explore
Sign in
derf
Travel-Routing-DE-HAFAS
Compare revisions
05661d3c9c695eb6ec57b1d8fe72e7274289bc27 to af3e8596bd62c780f35357b97fb45829dd456c2f
Commits on Source (2)
add via_stop support
· 7285e2ed
Birte Kristina Friesel
authored
Mar 24, 2024
7285e2ed
support multiple via stops
· af3e8596
Birte Kristina Friesel
authored
Mar 24, 2024
af3e8596
Hide whitespace changes
Inline
Side-by-side
bin/hafas
View file @
af3e8596
...
...
@@ -77,15 +77,17 @@ if ($list_services) {
parse_mot_options
();
my
(
$from_stop
,
$to_stop
)
=
@ARGV
;
my
(
$from_stop
,
@via_stops
)
=
@ARGV
;
my
$to_stop
=
pop
@via_stops
;
if
(
not
$from_stop
and
$to_stop
)
{
if
(
not
(
$from_stop
and
$to_stop
)
)
{
show_help
(
1
);
}
my
%opt
=
(
service
=>
$service
,
from_stop
=>
$from_stop
,
via_stops
=>
\
@via_stops
,
to_stop
=>
$to_stop
,
excluded_mots
=>
\
@excluded_mots
,
exclusive_mots
=>
\
@exclusive_mots
,
...
...
@@ -450,7 +452,7 @@ hafas - Interface to HAFAS (e.g. Deutsche Bahn) itinerary services
=head1 SYNOPSIS
B<hafas> [B<-d> I<date>] [B<-t> I<time>] [B<-m> I<motlist>]
[B<-s> I<service>] [B<-l> I<language>] [B<-v>] I<from> I<to>
[B<-s> I<service>] [B<-l> I<language>] [B<-v>] I<from>
[I<via> ...]
I<to>
=head1 VERSION
...
...
lib/Travel/Routing/DE/HAFAS.pm
View file @
af3e8596
...
...
@@ -218,6 +218,7 @@ sub new {
messages
=>
[]
,
results
=>
[]
,
from_stop
=>
$conf
{
from_stop
},
via_stops
=>
$conf
{
via_stops
}
//
[]
,
to_stop
=>
$conf
{
to_stop
},
ua
=>
$ua
,
now
=>
$now
,
...
...
@@ -231,33 +232,23 @@ sub new {
my
$time
=
(
$conf
{
datetime
}
//
$now
)
->
strftime
('
%H%M%S
');
my
$outFrwd
=
$conf
{
arrival
}
?
\
0
:
undef
;
my
(
$from_lid
,
$to_lid
);
if
(
$self
->
{
from_stop
}
=~
m{ ^ [0-9]+ $ }x
)
{
$from_lid
=
'
A=1@L=
'
.
$self
->
{
from_stop
}
.
'
@
';
}
else
{
$from_lid
=
'
A=1@O=
'
.
$self
->
{
from_stop
}
.
'
@
';
}
if
(
$self
->
{
to_stop
}
=~
m{ ^ [0-9]+ $ }x
)
{
$to_lid
=
'
A=1@L=
'
.
$self
->
{
to_stop
}
.
'
@
';
}
else
{
$to_lid
=
'
A=1@O=
'
.
$self
->
{
to_stop
}
.
'
@
';
}
my
@via_locs
=
map
{
$self
->
stop_to_hafas
(
$_
)
}
@
{
$self
->
{
via_stops
}
};
$req
=
{
svcReqL
=>
[
{
meth
=>
'
TripSearch
',
req
=>
{
depLocL
=>
[
{
lid
=>
$from_lid
}
],
arrLocL
=>
[
{
lid
=>
$to_lid
}
],
numF
=>
6
,
maxChg
=>
$conf
{
max_change
},
depLocL
=>
[
$self
->
stop_to_hafas
(
$self
->
{
from_stop
}
)
],
arrLocL
=>
[
$self
->
stop_to_hafas
(
$self
->
{
to_stop
}
)
],
numF
=>
6
,
maxChg
=>
$conf
{
max_change
},
minChgTime
=>
undef
,
outFrwd
=>
$outFrwd
,
viaLocL
=>
undef
,
trfReq
=>
{
viaLocL
=>
@via_locs
?
[
map
{
{
loc
=>
$_
}
}
@via_locs
]
:
undef
,
trfReq
=>
{
cType
=>
'
PK
',
tvlrProf
=>
[
{
type
=>
'
E
'
}
],
},
...
...
@@ -414,6 +405,17 @@ sub mot_mask {
return
$mot_mask
;
}
sub
stop_to_hafas
{
my
(
$self
,
$stop
)
=
@_
;
if
(
$stop
=~
m{ ^ [0-9]+ $ }x
)
{
return
{
lid
=>
'
A=1@L=
'
.
$stop
.
'
@
'
};
}
else
{
return
{
lid
=>
'
A=1@O=
'
.
$stop
.
'
@
'
};
}
}
sub
post_with_cache
{
my
(
$self
,
$url
)
=
@_
;
my
$cache
=
$self
->
{
cache
};
...
...
@@ -709,6 +711,11 @@ must be specified either by name or by EVA ID (e.g. 8000080 for Dortmund Hbf).
Destination stop, e.g. "Essen HBf" or "Alfredusbad, Essen (Ruhr)". The stop
must be specified either by name or by EVA ID (e.g. 8000080 for Dortmund Hbf).
=item B<via_stops> => [I<stop1>, I<stop2>, ...]
Only return connections that pass all specified stops. Individual stops are
identified by name or by EVA ID (e.g. 8000080 for Dortmund Hbf).
=item B<arrival> => I<bool>
If true: request connections that arrive at the destination before the
...
...