From ac81019e73049c079d3b9ea8c4187a04bc1833f4 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 29 Apr 2016 14:20:16 +0200 Subject: improved show info output moved command line parsing of week and dow to lib diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm index 7f060e9..3835851 100755 --- a/lib/RHRD/utils.pm +++ b/lib/RHRD/utils.pm @@ -66,6 +66,9 @@ use constant { DB_PARAM_DOW_HINT => "must be between 1 and 7 (1=Monday, ..., 7=Sunday)", DB_PARAM_STARTTIME_HINT => "must be in format HHMM (without seperator) in 24 hour format", DB_PARAM_LEN_HINT => "must be a positive number below 1440", + + CMDLINE_WEEK_HINT => "must be one of W1, W2, W3, W4", + CMDLINE_DOW_HINT => "must be one of MO, TU, WE, TH, FR, SA, SU", }; sub dropbox_param_type_ok @@ -118,6 +121,44 @@ sub dropbox_param_len_ok return (1, 'OK', DB_PARAM_LEN_HINT); } +sub cmdline_rdweek +{ + my ($dow) = @_; + + if(uc($dow) eq "W1") { + return (1, 'OK', CMDLINE_WEEK_HINT); + } elsif(uc($dow) eq "W2") { + return (2, 'OK', CMDLINE_WEEK_HINT); + } elsif(uc($dow) eq "W3") { + return (3, 'OK', CMDLINE_WEEK_HINT); + } elsif(uc($dow) eq "W4") { + return (4, 'OK', CMDLINE_WEEK_HINT); + } + return (undef, 'invalid week', CMDLINE_WEEK_HINT); +} + +sub cmdline_dow +{ + my ($dow) = @_; + + if(uc($dow) eq "MO") { + return (1, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "TU") { + return (2, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "WE") { + return (3, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "TH") { + return (4, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "FR") { + return (5, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "SA") { + return (6, 'OK', CMDLINE_DOW_HINT); + } elsif(uc($dow) eq "SU") { + return (7, 'OK', CMDLINE_DOW_HINT); + } + return (undef, 'invalid day-of-week', CMDLINE_DOW_HINT); +} + sub fetch_parse_json { my ($url, $ua_str) = @_; diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules index fa52226..2d509a9 100755 --- a/utils/rhrd-schedules +++ b/utils/rhrd-schedules @@ -144,45 +144,31 @@ sub show__day # (W1|W2|W3|W4|ALL) sub parse_rdweek { - my ($dow) = @_; - - if(uc($dow) eq "W1") { - return(1); - } elsif(uc($dow) eq "W2") { - return(2); - } elsif(uc($dow) eq "W3") { - return(3); - } elsif(uc($dow) eq "W4") { - return(4); - } elsif(uc($dow) eq "ALL") { - return(1, 2, 3, 4); + my ($week) = @_; + if(uc($week) eq "ALL") { + return (1, 2, 3, 4); } - return (); + my ($w, undef, $hint) = RHRD::utils::cmdline_rdweek($week); + unless(defined($w)) { + print "error parsing week: $week, " . $hint . " or ALL\n"; + return (); + } + return $w; } # (MO|TU|WE|TH|FR|SA|SU|ALL) sub parse_dow { my ($dow) = @_; - - if(uc($dow) eq "MO") { - return(1); - } elsif(uc($dow) eq "TU") { - return(2); - } elsif(uc($dow) eq "WE") { - return(3); - } elsif(uc($dow) eq "TH") { - return(4); - } elsif(uc($dow) eq "FR") { - return(5); - } elsif(uc($dow) eq "SA") { - return(6); - } elsif(uc($dow) eq "SU") { - return(7); - } elsif(uc($dow) eq "ALL") { - return(1, 2, 3, 4, 5, 6, 7); + if(uc($dow) eq "ALL") { + return (1, 2, 3, 4, 5, 6, 7); } - return (); + my ($d, undef, $hint) = RHRD::utils::cmdline_dow($dow); + unless(defined($d)) { + print "error parsing day of week: $dow, " . $hint . " or ALL\n"; + return (); + } + return $d; } sub cmp_dates @@ -204,15 +190,10 @@ sub gen_dates my ($week, $dow) = @_; my @weeks = parse_rdweek($week); - unless(@weeks) { - print "error parsing week: $week, must be one of W1, W2, W3, W4, ALL\n"; - return () - } + return () unless(@weeks); my @dows = parse_dow($dow); - unless(@dows) { - print "error parsing day of week: $dow, must be one of MO, TU, WE, TH, FR, SA, SU, ALL\n"; - return () - } + return () unless(@dows); + my $curweek = RHRD::utils::get_rd_week(); my @today = Date::Calc::Today(); diff --git a/utils/rhrd-show b/utils/rhrd-show index a25ceff..3cac649 100755 --- a/utils/rhrd-show +++ b/utils/rhrd-show @@ -23,6 +23,7 @@ use strict; use RHRD::rddb; use RHRD::utils; +use Date::Calc; sub print_usage { @@ -55,15 +56,14 @@ sub show print STDERR "$carts[1]: $carts[2]\n"; return 1; } - my ($title, undef, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($ctx, $show_id); - unless (defined $title) { + my ($show, $status, $errorstring) = RHRD::rddb::get_show_info($ctx, $show_id); + unless (defined $show) { print STDERR "$errorstring\n"; return 1; } - print $title . ":\n"; - for my $cart (@carts) { - print " > " . $cart . "\n"; - } + $show->{'DOW'} = 7 if $show->{'DOW'} == 0; + print $show->{'TITLE'} . ": " . join(", ", $show->{'RHYTHM'}, Date::Calc::Day_of_Week_to_Text($show->{'DOW'}), $show->{'STARTTIME'}, ($show->{'LEN'} . " min")) . "\n"; + print " carts(" . scalar(@carts) . "): " . join(", ", @carts) . " \n"; return 0; } @@ -96,7 +96,7 @@ sub add__check_arguments return 1; } - ($result, $err, $hint) = RHRD::utils::dropbox_param_dow_ok($dow); + ($result, $err, $hint) = RHRD::utils::cmdline_dow($dow); unless($result) { print STDERR $err . "\n " . $hint . "\n"; return 1; @@ -125,6 +125,7 @@ sub add if($ret) { return $ret; } + ($dow, undef, undef) = RHRD::utils::cmdline_dow($dow); print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n"; -- cgit v0.10.2