diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-06-09 13:13:56 +0200 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-06-09 13:13:56 +0200 | 
| commit | ccdfc0206f849ccaeee8f5a5093c51d1274d2652 (patch) | |
| tree | a30deb0179ef95a01360161020dd85dfe1d1823d /lib/Travelynx/Command/work.pm | |
| parent | 3322ca23669871fff79a229b9167f2e3169c4352 (diff) | |
Add (possibly still somewhat experimental) MOTIS support
Squashed commit of the following:
commit c7c8b2ec5d8254eefb548bfe7763a7d8c9558be4
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Mon Jun 9 13:08:57 2025 +0200
    fix another merge issue
commit d2ae55c901ab59284263ad3070ba425e03cee833
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Mon Jun 9 13:08:39 2025 +0200
    Stations: get_by_external_id is a slow function
commit 725174413300e71c350d2f1dcfbeacd751def977
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Mon Jun 9 13:05:48 2025 +0200
    ... I accidentally commited a merge conflict
commit c695494dbd6aaf252199da42ad763bdffa1d64b9
Merge: e5da62b 3322ca2
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Mon Jun 9 12:46:08 2025 +0200
    Merge branch 'main' into motis
commit e5da62bcfc7953d5109ba53ae1fcc34f509f251b
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Wed Apr 30 18:15:39 2025 +0200
    cpanfile: add Travel::Status::MOTIS dependency
commit 180723a9e0e2f0aede0bc6352d5eee601183ccef
Merge: 479373b c90ae4c
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Wed Apr 30 18:13:45 2025 +0200
    Merge branch 'main' into motis
commit 479373b14eaadbc022199df246c9fb523a87188c
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Wed Apr 30 18:06:41 2025 +0200
    database: remove duplicate users_with_backend migration
commit 94c8b5a7d1e2cb7f73b0eca7e33d916775504cd4
Author: Birte Kristina Friesel <derf@finalrewind.org>
Date:   Wed Apr 30 18:06:04 2025 +0200
    Do not store train colours in database. They're only supported by MOTIS.
commit d58f23c3c7b06cc0243c1945dacd8673d2d2e428
Author: networkException <git@nwex.de>
Date:   Fri Apr 18 11:47:02 2025 +0200
    Initial MOTIS backend support
    This patch adds support for checkins using MOTIS backends
    using the Travel::Status::MOTIS module.
    With this travelynx supports the two services currently
    exposed by the module, RNV for local transit in Mannheim,
    Germany and surrounding cities and transitous for worldwide
    crowdsourced tranit feeds.
    This implementation supports realtime predictions,
    cancellations and polylines as well as custom route colors
    if available.
    As MOTIS doesn't expose names of indivial trips currently,
    displaying transports is mostly limited to route names.
    MOTIS uses strings for stop ids, based on the used GTFS
    source feeds. As travelynx's data model currently assumes
    interger station ids, this patch adds a mapping table
    to the database.
    This patch assumes support for MOTIS in db-fakedisplay.
    Note that while träwelling has migrated to tranitous fully
    sync remains unsupported for now.
    See https://github.com/Traewelling/traewelling/issues/3345
Diffstat (limited to 'lib/Travelynx/Command/work.pm')
| -rw-r--r-- | lib/Travelynx/Command/work.pm | 95 | 
1 files changed, 95 insertions, 0 deletions
| diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 4876e98..4ff5c9e 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -1,6 +1,7 @@  package Travelynx::Command::work;  # Copyright (C) 2020-2023 Birte Kristina Friesel +# Copyright (C) 2025 networkException <git@nwex.de>  #  # SPDX-License-Identifier: AGPL-3.0-or-later  use Mojo::Base 'Mojolicious::Command'; @@ -184,6 +185,100 @@ sub run {  			next;  		} +		if ( $entry->{is_motis} ) { + +			eval { +				$self->app->motis->trip_id( +					service => $entry->{backend_name}, +					trip_id => $train_id, +				)->then( +					sub { +						my ($journey) = @_; + +						for my $stopover ( $journey->stopovers ) { +							if ( not defined $stopover->stop->{eva} ) { +								my $stop = $self->app->stations->get_by_external_id( +									external_id => $stopover->stop->id, +									motis       => $entry->{backend_name}, +								); + +								$stopover->stop->{eva} = $stop->{eva}; +							} +						} + +						my $found_departure; +						my $found_arrival; +						for my $stopover ( $journey->stopovers ) { +							if ( $stopover->stop->{eva} == $dep ) { +								$found_departure = $stopover; +							} + +							if ( $arr and $stopover->stop->{eva} == $arr ) { +								$found_arrival = $stopover; +								last; +							} +						} + +						if ( not $found_departure ) { +							$self->app->log->debug("Did not find $dep within trip $train_id"); +							return; +						} + +						if ( $found_departure->realtime_departure ) { +							$self->app->in_transit->update_departure_motis( +								uid      => $uid, +								journey  => $journey, +								stopover => $found_departure, +								dep_eva  => $dep, +								arr_eva  => $arr, +								train_id => $train_id, +							); +						} + +						if ( $found_arrival and $found_arrival->realtime_arrival ) { +							$self->app->in_transit->update_arrival_motis( +								uid      => $uid, +								journey  => $journey, +								train_id => $train_id, +								stopover => $found_arrival, +								dep_eva  => $dep, +								arr_eva  => $arr +							); +						} +					} +				)->catch( +					sub { +						my ($err) = @_; +						$self->app->log->error( +"work($uid) @ MOTIS $entry->{backend_name}: journey: $err" +						); +						if ( $err =~ m{HTTP 429} ) { +							$dbris_rate_limited = 1; +						} +					} +				)->wait; + +				if (    $arr +					and $entry->{real_arr_ts} +					and $now->epoch - $entry->{real_arr_ts} > 600 ) +				{ +					$self->app->checkout_p( +						station => $arr, +						force   => 2, +						dep_eva => $dep, +						arr_eva => $arr, +						uid     => $uid +					)->wait; +				} +			}; +			if ($@) { +				$errors += 1; +				$self->app->log->error( +					"work($uid) @ MOTIS $entry->{backend_name}: $@"); +			} +			next; +		} +  		if ( $entry->{is_hafas} ) {  			eval { | 
