summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-04-19 11:01:24 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-04-19 11:01:24 +0200
commit8ccf3d2271dbe21be209ab70b557ce4d437fe97d (patch)
tree355e333dbafc6a2aaf9148aeef17c2cb291f5016
parent61f8adb24919b19e48b4d74717e6b4a8fbd5f7b5 (diff)
add devmode switch to enable/disable debug/developer output
-rwxr-xr-xbin/db-iris13
-rw-r--r--lib/Travel/Status/DE/IRIS.pm12
2 files changed, 16 insertions, 9 deletions
diff --git a/bin/db-iris b/bin/db-iris
index 310de21..684e80a 100755
--- a/bin/db-iris
+++ b/bin/db-iris
@@ -19,8 +19,9 @@ use Travel::Status::DE::IRIS;
use Travel::Status::DE::IRIS::Stations;
my ( $date, $time, $lookahead );
-my $datetime = DateTime->now( time_zone => 'Europe/Berlin' );
-my $realtime = 0;
+my $datetime = DateTime->now( time_zone => 'Europe/Berlin' );
+my $developer_mode = 0;
+my $realtime = 0;
my ( $filter_via, $track_via, $status_via );
my ( @grep_class, @grep_type, @grep_platform );
my ( %edata, @edata_pre );
@@ -43,6 +44,7 @@ GetOptions(
'T|type=s' => \@grep_type,
'v|via=s' => \$filter_via,
'V|track-via=s' => \$track_via,
+ 'devmode' => \$developer_mode,
'version' => \&show_version,
) or show_help(1);
@@ -98,9 +100,10 @@ for my $efield (@edata_pre) {
}
my $status = Travel::Status::DE::IRIS->new(
- datetime => $datetime,
- lookahead => $lookahead,
- station => $station,
+ datetime => $datetime,
+ developer_mode => $developer_mode,
+ lookahead => $lookahead,
+ station => $station,
);
if ($track_via) {
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index eb4ae10..bd2a784 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -28,6 +28,7 @@ sub new {
my $self = {
datetime => $opt{datetime}
// DateTime->now( time_zone => 'Europe/Berlin' ),
+ developer_mode => $opt{developer_mode},
iris_base => $opt{iris_base}
// 'http://iris.noncd.db.de/iris-tts/timetable',
lookahead => $opt{lookahead} // ( 4 * 60 ),
@@ -173,7 +174,10 @@ sub get_timetable {
my $res = $ua->get(
$dt->strftime( $self->{iris_base} . "/plan/${eva}/%y%m%d/%H" ) );
- #say 'GET ' . $dt->strftime( $self->{iris_base} . "/plan/${eva}/%y%m%d/%H" );
+ if ( $self->{developer_mode} ) {
+ say 'GET '
+ . $dt->strftime( $self->{iris_base} . "/plan/${eva}/%y%m%d/%H" );
+ }
if ( $res->is_error ) {
$self->{warnstr} = 'Failed to fetch a schedule part: Server returned '
@@ -183,8 +187,6 @@ sub get_timetable {
my $xml = XML::LibXML->load_xml( string => $res->decoded_content );
- #say $xml->toString(1);
-
my $station = ( $xml->findnodes('/timetable') )[0]->getAttribute('station');
for my $s ( $xml->findnodes('/timetable/s') ) {
@@ -201,7 +203,9 @@ sub get_realtime {
my $eva = $self->{nodes}{station}->getAttribute('eva');
my $res = $self->{user_agent}->get( $self->{iris_base} . "/fchg/${eva}" );
- #say 'GET ' . $self->{iris_base} . "/fchg/${eva}";
+ if ( $self->{developer_mode} ) {
+ say 'GET ' . $self->{iris_base} . "/fchg/${eva}";
+ }
if ( $res->is_error ) {
$self->{warnstr} = 'Failed to fetch realtime data: Server returned '