From fc63aa732e54d8ed072a9f939de43efdcd855fc6 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 20 May 2016 15:54:40 +0200 Subject: added rhrd-show search diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index a1ab7e6..62146b5 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -1052,9 +1052,9 @@ sub list_shows { my ($ctx, $groupname) = @_; - my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME = ? order by TO_CART;}; + my $sql = qq{select GROUP_NAME,TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME = ? order by TO_CART;}; if(defined($groupname)) { - $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME = ? and GROUP_NAME = ? order by TO_CART;}; + $sql = qq{select GROUP_NAME,TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME = ? and GROUP_NAME = ? order by TO_CART;}; } my $sth = $ctx->{'dbh'}->prepare($sql) @@ -1069,7 +1069,7 @@ sub list_shows } my @show_dbs; - while(my ($to_cart, $params) = $sth->fetchrow_array()) { + while(my ($group, $to_cart, $params) = $sth->fetchrow_array()) { my @p = split(';', $params); next if ('S' ne $p[0]); @@ -1080,6 +1080,7 @@ sub list_shows $sth->finish(); return (undef, $status, $errorstring); } + $entry->{'GROUP'} = $group; $entry->{'TITLE'} = $title; $entry->{'LOG'} = $log; $entry->{'RHYTHM'} = $p[1]; diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules index 123302c..4f07db5 100755 --- a/utils/rhrd-schedules +++ b/utils/rhrd-schedules @@ -21,6 +21,9 @@ # use strict; + +use lib '../lib'; + use RHRD::rddb; use RHRD::utils; use DateTime; diff --git a/utils/rhrd-show b/utils/rhrd-show index 880ac5e..58ed014 100755 --- a/utils/rhrd-show +++ b/utils/rhrd-show @@ -28,6 +28,7 @@ use Date::Calc; sub print_usage { print STDERR "Usage: rhrd-show list [ ]\n" . + " rhrd-show search \n" . " rhrd-show (show|remove) \n" . " rhrd-show add <num-carts> <rhythm> <dow> <starttime> <len>\n" . " rhrd-show edit <show-id> <title> <rhythm> <dow> <starttime> <len>\n"; @@ -49,6 +50,27 @@ sub list return 0; } +sub search +{ + my ($ctx, $searchexp) = @_; + + my @shows = RHRD::rddb::list_shows($ctx); + if(!defined $shows[0] && defined $shows[1]) { + print STDERR "$shows[1]: $shows[2]"; + return 1; + } + my @sorted = sort { lc($a->{'TITLE'}) cmp lc($b->{'TITLE'}) } @shows; + for my $show (@sorted) { + next unless $show->{'TITLE'} =~ /$searchexp/i; + + $show->{'DOW'} = 7 if $show->{'DOW'} == 0; + print $show->{'ID'} . ": " . $show->{'TITLE'} . ", "; + print join(", ", $show->{'RHYTHM'}, Date::Calc::Day_of_Week_to_Text($show->{'DOW'}), $show->{'STARTTIME'}, ($show->{'LEN'} . " min")); + print ", group: " . $show->{'GROUP'} . "\n"; + } + return 0; +} + sub show { my ($ctx, $showid) = @_; @@ -70,7 +92,6 @@ sub show } - sub add__check_arguments { my ($groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_; @@ -294,6 +315,14 @@ if(defined $ctx) { $ret = list($ctx, $ARGV[1]) } } + elsif($cmd eq "search") { + if($num_args != 2) { + print_usage(); + $ret = 1; + } else { + $ret = search($ctx, $ARGV[1]) + } + } elsif($cmd eq "show") { if($num_args != 2) { print_usage(); -- cgit v0.10.2