2024-02-09 18:09:16 +00:00
|
|
|
package Travelynx::Command::dumpstops;
|
|
|
|
|
|
|
|
# Copyright (C) 2024 Birte Kristina Friesel
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Command';
|
|
|
|
use List::Util qw();
|
|
|
|
use Text::CSV;
|
|
|
|
|
2024-06-15 08:36:18 +00:00
|
|
|
has description => 'Export known stops to CSV';
|
2024-02-09 18:09:16 +00:00
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage };
|
|
|
|
|
|
|
|
sub run {
|
|
|
|
my ( $self, $command, $filename ) = @_;
|
|
|
|
my $db = $self->app->pg->db;
|
|
|
|
|
|
|
|
if ( not $command or not $filename ) {
|
|
|
|
$self->help;
|
|
|
|
}
|
|
|
|
elsif ( $command eq 'csv' ) {
|
2024-04-07 09:23:35 +00:00
|
|
|
open( my $fh, '>:encoding(utf-8)', $filename )
|
|
|
|
or die("open($filename): $!\n");
|
2024-02-09 18:09:16 +00:00
|
|
|
|
|
|
|
my $csv = Text::CSV->new( { eol => "\r\n" } );
|
2024-08-07 10:13:15 +00:00
|
|
|
$csv->combine(qw(name eva lat lon backend is_iris is_hafas));
|
2024-02-09 18:09:16 +00:00
|
|
|
print $fh $csv->string;
|
|
|
|
|
|
|
|
my $iter = $self->app->stations->get_db_iterator;
|
|
|
|
while ( my $row = $iter->hash ) {
|
2024-08-07 10:13:15 +00:00
|
|
|
$csv->combine(
|
|
|
|
@{$row}{qw{name eva lat lon backend is_iris is_hafas}} );
|
2024-02-09 18:09:16 +00:00
|
|
|
print $fh $csv->string;
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->help;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
Usage: index.pl dumpstops <format> <filename>
|
|
|
|
|
|
|
|
Exports known stops to <filename>.
|
|
|
|
Right now, only the "csv" format is supported.
|