summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-04-19 18:26:20 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-04-19 18:26:20 +0200
commitf5fd6d42e11bc8f6a5bd84a3653a40fa03ed5497 (patch)
treea90e7c9cbee985ac44403fdcadb764c4966246ab /lib/Travelynx/Controller
parent020fe826606e8d02d326c7de8a8df758588f424b (diff)
Add CSV Export
Diffstat (limited to 'lib/Travelynx/Controller')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index ae5be69..702a89e 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -7,6 +7,7 @@ use JSON;
use List::Util qw(uniq min max);
use List::UtilsBy qw(max_by uniq_by);
use List::MoreUtils qw(first_index);
+use Text::CSV;
use Travel::Status::DE::IRIS::Stations;
sub homepage {
@@ -644,6 +645,54 @@ sub json_history {
$self->render( json => [ $self->get_user_travels ] );
}
+sub csv_history {
+ my ($self) = @_;
+
+ my $csv = Text::CSV->new( { eol => "\r\n" } );
+ my $buf = q{};
+
+ $csv->combine(
+ qw(Zugtyp Linie Nummer Start Ziel),
+ 'Start (DS100)',
+ 'Ziel (DS100)',
+ 'Abfahrt (soll)',
+ 'Abfahrt (ist)',
+ 'Ankunft (soll)',
+ 'Ankunft (ist)',
+ 'Kommentar',
+ 'ID'
+ );
+ $buf .= $csv->string;
+
+ for my $journey ( $self->get_user_travels( with_datetime => 1 ) ) {
+ if (
+ $csv->combine(
+ $journey->{type},
+ $journey->{line},
+ $journey->{no},
+ $journey->{from_name},
+ $journey->{to_name},
+ $journey->{from_ds100},
+ $journey->{to_ds100},
+ $journey->{sched_departure}->strftime('%Y-%m-%d %H:%M'),
+ $journey->{rt_departure}->strftime('%Y-%m-%d %H:%M'),
+ $journey->{sched_arrival}->strftime('%Y-%m-%d %H:%M'),
+ $journey->{rt_arrival}->strftime('%Y-%m-%d %H:%M'),
+ $journey->{user_data}{comment} // q{},
+ $journey->{id}
+ )
+ )
+ {
+ $buf .= $csv->string;
+ }
+ }
+
+ $self->render(
+ text => $buf,
+ format => 'csv'
+ );
+}
+
sub yearly_history {
my ($self) = @_;
my $year = $self->stash('year');