diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-01-08 10:54:54 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-01-08 14:36:31 +0100 |
commit | 1233796866b332dbefc4c739acb0ea5932916537 (patch) | |
tree | fb83a27ea8d59b525a9bee9e8d8dd1b970a25cda /lib | |
parent | 71fa4468006c943ff2d20eb52af45301fe41cfad (diff) |
Traewelling: Use API v1 for pull sync1.21.4
API v0 has occasional performance issues and is not a preferable
maintenance target
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx.pm | 1 | ||||
-rw-r--r-- | lib/Travelynx/Helper/Traewelling.pm | 39 |
2 files changed, 19 insertions, 21 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 8138a35..b7284e4 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -2289,6 +2289,7 @@ sub startup { } } else { + $self->log->debug("... train $traewelling->{line} not found"); $self->traewelling->log( uid => $uid, message => diff --git a/lib/Travelynx/Helper/Traewelling.pm b/lib/Travelynx/Helper/Traewelling.pm index 88b91a0..03db4d2 100644 --- a/lib/Travelynx/Helper/Traewelling.pm +++ b/lib/Travelynx/Helper/Traewelling.pm @@ -74,7 +74,8 @@ sub get_status_p { }; $self->{user_agent}->request_timeout(20) - ->get_p( "https://traewelling.de/api/v0/user/${username}" => $header ) + ->get_p( + "https://traewelling.de/api/v1/user/${username}/statuses" => $header ) ->then( sub { my ($tx) = @_; @@ -84,33 +85,29 @@ sub get_status_p { return; } else { - if ( my $status = $tx->result->json->{statuses}{data}[0] ) { + if ( my $status = $tx->result->json->{data}[0] ) { my $status_id = $status->{id}; my $message = $status->{body}; my $checkin_at - = $self->parse_datetime( $status->{created_at} ); + = $self->parse_datetime( $status->{createdAt} ); my $dep_dt = $self->parse_datetime( - $status->{train_checkin}{departure} ); + $status->{train}{origin}{departurePlanned} ); my $arr_dt = $self->parse_datetime( - $status->{train_checkin}{arrival} ); + $status->{train}{destination}{arrivalPlanned} ); my $dep_eva - = $status->{train_checkin}{origin}{ibnr}; + = $status->{train}{origin}{rilIdentifier}; my $arr_eva - = $status->{train_checkin}{destination}{ibnr}; + = $status->{train}{destination}{rilIdentifier}; my $dep_name - = $status->{train_checkin}{origin}{name}; + = $status->{train}{origin}{name}; my $arr_name - = $status->{train_checkin}{destination}{name}; - - my $category - = $status->{train_checkin}{hafas_trip}{category}; - my $trip_id - = $status->{train_checkin}{hafas_trip}{trip_id}; - my $linename - = $status->{train_checkin}{hafas_trip}{linename}; + = $status->{train}{destination}{name}; + + my $category = $status->{train}{category}; + my $linename = $status->{train}{lineName}; my ( $train_type, $train_line ) = split( qr{ }, $linename ); $promise->resolve( { @@ -123,7 +120,6 @@ sub get_status_p { arr_dt => $arr_dt, arr_eva => $arr_eva, arr_name => $arr_name, - trip_id => $trip_id, train_type => $train_type, line => $linename, line_no => $train_line, @@ -341,7 +337,7 @@ sub checkin { destination => q{} . $opt{arr_eva}, departure => $departure_ts, arrival => $arrival_ts, - toot => $opt{data}{toot} ? \1 : \0, + toot => $opt{data}{toot} ? \1 : \0, tweet => $opt{data}{tweet} ? \1 : \0, }; @@ -350,8 +346,9 @@ sub checkin { } $self->{user_agent}->request_timeout(20) - ->post_p( "https://traewelling.de/api/v0/trains/checkin" => - $header => json => $request )->then( + ->post_p( + "https://traewelling.de/api/v0/trains/checkin" => $header => json => + $request )->then( sub { my ($tx) = @_; if ( my $err = $tx->error ) { @@ -363,7 +360,7 @@ sub checkin { $self->{log}->debug("Traewelling checkin error: $err_msg"); } $self->{model}->log( - uid => $opt{uid}, + uid => $opt{uid}, message => "Fehler bei $opt{train_type} $opt{train_no}: $err_msg", is_error => 1 |