From 1184d848277a280fb5c5ef8da6a06bec87db15eb Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 23 Jun 2024 10:28:51 +0200 Subject: [PATCH] =?UTF-8?q?always=20use=20HAFAS=20for=20traewelling=20?= =?UTF-8?q?=E2=86=92=20travelynx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Travelynx.pm | 247 ++++++++++------------------------------------- 1 file changed, 49 insertions(+), 198 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 2f8396c..6aa0139 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1958,224 +1958,75 @@ sub startup { return $promise->resolve; } - if ( $traewelling->{category} - !~ m{^ (?: national .* | regional .* | suburban ) $ }x ) - { + my $db = $self->pg->db; + my $tx = $db->begin; - my $db = $self->pg->db; - my $tx = $db->begin; - - $self->checkin_p( - station => $traewelling->{dep_eva}, - train_id => $traewelling->{trip_id}, - uid => $uid, - in_transaction => 1, - db => $db - )->then( - sub { - $self->log->debug("... handled origin"); - return $self->checkout_p( - station => $traewelling->{arr_eva}, - train_id => $traewelling->{trip_id}, - uid => $uid, - in_transaction => 1, - db => $db - ); - } - )->then( - sub { - my ( undef, $err ) = @_; - if ($err) { - $self->log->debug("... error: $err"); - return Mojo::Promise->reject($err); - } - $self->log->debug("... handled destination"); - if ( $traewelling->{message} ) { - $self->in_transit->update_user_data( - uid => $uid, - db => $db, - user_data => - { comment => $traewelling->{message} } - ); - } - $self->traewelling->log( - uid => $uid, - db => $db, - message => -"Eingecheckt in $traewelling->{line} nach $traewelling->{arr_name}", - status_id => $traewelling->{status_id}, - ); - $self->traewelling->set_latest_pull_status_id( - uid => $uid, - status_id => $traewelling->{status_id}, - db => $db - ); - - $tx->commit; - $promise->resolve; - return; - } - )->catch( - sub { - my ($err) = @_; - $self->log->debug("... error: $err"); - $self->traewelling->log( - uid => $uid, - message => -"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $err", - status_id => $traewelling->{status_id}, - is_error => 1 - ); - $promise->resolve; - return; - } - )->wait; - return $promise; - } - - $self->iris->get_departures_p( - station => $traewelling->{dep_eva}, - lookbehind => 60, - lookahead => 40 + $self->_checkin_hafas_p( + hafas => 'DB', + station => $traewelling->{dep_eva}, + train_id => $traewelling->{trip_id}, + uid => $uid, + in_transaction => 1, + db => $db )->then( sub { - my ($dep) = @_; - my ( $train_ref, $train_id ); - - if ( $dep->{errstr} ) { - $self->traewelling->log( - uid => $uid, - message => -"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $dep->{errstr}", - status_id => $traewelling->{status_id}, - is_error => 1, - ); - $promise->resolve; - return; - } - - for my $train ( @{ $dep->{results} } ) { - if ( $train->line ne $traewelling->{line} ) { - next; - } - if ( not $train->sched_departure - or $train->sched_departure->epoch - != $traewelling->{dep_dt}->epoch ) - { - next; - } - if ( - not - List::Util::first { $_ eq $traewelling->{arr_name} } - $train->route_post - ) - { - next; - } - $train_id = $train->train_id; - $train_ref = $train; - last; - } - - if ( not $train_id ) { - $self->log->debug( - "... train $traewelling->{line} not found"); - $self->traewelling->log( - uid => $uid, - message => -"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: Zug nicht gefunden", - status_id => $traewelling->{status_id}, - is_error => 1 - ); - return $promise->resolve; - } - - $self->log->debug("... found train: $train_id"); - - my $db = $self->pg->db; - my $tx = $db->begin; - - $self->checkin_p( - station => $traewelling->{dep_eva}, - train_id => $train_id, + $self->log->debug("... handled origin"); + return $self->_checkout_hafas_p( + hafas => 'DB', + station => $traewelling->{arr_eva}, + train_id => $traewelling->{trip_id}, uid => $uid, in_transaction => 1, db => $db - )->then( - sub { - $self->log->debug("... handled origin"); - return $self->checkout_p( - station => $traewelling->{arr_eva}, - train_id => 0, - uid => $uid, - in_transaction => 1, - db => $db - ); - } - )->then( - sub { - my ( undef, $err ) = @_; - if ($err) { - $self->log->debug("... error: $err"); - return Mojo::Promise->reject($err); - } - $self->log->debug("... handled destination"); - if ( $traewelling->{message} ) { - $self->in_transit->update_user_data( - uid => $uid, - db => $db, - user_data => - { comment => $traewelling->{message} } - ); - } - $self->traewelling->log( - uid => $uid, - db => $db, - message => + ); + } + )->then( + sub { + my ( undef, $err ) = @_; + if ($err) { + $self->log->debug("... error: $err"); + return Mojo::Promise->reject($err); + } + $self->log->debug("... handled destination"); + if ( $traewelling->{message} ) { + $self->in_transit->update_user_data( + uid => $uid, + db => $db, + user_data => { comment => $traewelling->{message} } + ); + } + $self->traewelling->log( + uid => $uid, + db => $db, + message => "Eingecheckt in $traewelling->{line} nach $traewelling->{arr_name}", - status_id => $traewelling->{status_id}, - ); - $self->traewelling->set_latest_pull_status_id( - uid => $uid, - status_id => $traewelling->{status_id}, - db => $db - ); + status_id => $traewelling->{status_id}, + ); + $self->traewelling->set_latest_pull_status_id( + uid => $uid, + status_id => $traewelling->{status_id}, + db => $db + ); - $tx->commit; - $promise->resolve; - return; - } - )->catch( - sub { - my ($err) = @_; - $self->log->debug("... error: $err"); - $self->traewelling->log( - uid => $uid, - message => -"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $err", - status_id => $traewelling->{status_id}, - is_error => 1 - ); - $promise->resolve; - return; - } - )->wait; + $tx->commit; + $promise->resolve; + return; } )->catch( sub { - my ( $err, $dep ) = @_; + my ($err) = @_; + $self->log->debug("... error: $err"); $self->traewelling->log( uid => $uid, message => -"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $dep->{errstr}", +"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $err", status_id => $traewelling->{status_id}, - is_error => 1, + is_error => 1 ); $promise->resolve; return; } )->wait; - return $promise; } );