Commit 7b01cae7 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Pass scheduled arrival and departure times to Traewelling API

parent 255d0610
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -38,6 +38,20 @@ sub new {
	return bless( \%opt, $class );
}

sub epoch_to_dt_or_undef {
	my ($epoch) = @_;

	if ( not $epoch ) {
		return undef;
	}

	return DateTime->from_epoch(
		epoch     => $epoch,
		time_zone => 'Europe/Berlin',
		locale    => 'de-DE',
	);
}

sub parse_datetime {
	my ( $self, $dt ) = @_;

@@ -309,12 +323,24 @@ sub checkin {
		'Authorization' => "Bearer $opt{token}",
	};

	my $departure_ts = epoch_to_dt_or_undef( $opt{dep_ts} );
	my $arrival_ts   = epoch_to_dt_or_undef( $opt{arr_ts} );

	if ($departure_ts) {
		$departure_ts = $departure_ts->rfc3339;
	}
	if ($arrival_ts) {
		$arrival_ts = $arrival_ts->rfc3339;
	}

	my $request = {
		tripID   => $opt{trip_id},
		lineName => $opt{train_type} . ' '
		  . ( $opt{train_line} // $opt{train_no} ),
		start       => q{} . $opt{dep_eva},
		destination => q{} . $opt{arr_eva},
		departure   => $departure_ts,
		arrival     => $arrival_ts,
		toot        => $opt{data}{toot} ? \1 : \0,
		tweet       => $opt{data}{tweet} ? \1 : \0,
	};
+4 −1
Original line number Diff line number Diff line
package Travelynx::Model::Traewelling;

# Copyright (C) 2020 Daniel Friesel
#
# SPDX-License-Identifier: AGPL-3.0-or-later
@@ -213,7 +214,9 @@ sub get_pushable_accounts {
			i.checkin_station_id as dep_eva, i.checkout_station_id as arr_eva,
			i.data as journey_data, i.train_type as train_type,
			i.train_line as train_line, i.train_no as train_no,
			extract(epoch from i.checkin_time) as checkin_ts
			extract(epoch from i.checkin_time) as checkin_ts,
			extract(epoch from i.sched_departure) as dep_ts,
			extract(epoch from i.sched_arrival) as arr_ts
			from traewelling as t
			join in_transit as i on t.user_id = i.user_id
			where t.push_sync = True