diff options
-rw-r--r-- | README | 2 | ||||
-rwxr-xr-x | rh-bin/schedules.json | 68 |
2 files changed, 47 insertions, 23 deletions
@@ -25,7 +25,7 @@ LICENSE Installation ============ -# sudo aptitude install apache2 libapache2-mpm-itk libapache2-mod-perl2 libjson-maybexs-perl librhrd-perl libjs-jquery +# sudo aptitude install apache2 libapache2-mpm-itk libapache2-mod-perl2 libjson-maybexs-perl librhrd-perl libdatetime-format-strptime-perl libjs-jquery # sudo a2enmod ssl perl # sudo /etc/init.d/apache2 restart diff --git a/rh-bin/schedules.json b/rh-bin/schedules.json index c7f82b0..ca01cfc 100755 --- a/rh-bin/schedules.json +++ b/rh-bin/schedules.json @@ -23,37 +23,61 @@ use strict; use RHRD::rddb; use JSON::MaybeXS; +use CGI; +use DateTime; +use DateTime::Format::Strptime; +use DateTime::Duration; my $status = 'ERROR'; my $errorstring = 'unknown'; my $responsecode = 500; my @showlist; -(my $ctx, $status, $errorstring) = RHRD::rddb::init(); -if(defined $ctx) { - my $year = 2016; - my $month = 06; - my $day = 23; - my @shows = RHRD::rddb::get_schedule_log($ctx, $year, $month, $day); - if(!defined $shows[0] && defined $shows[1]) { - $responsecode = 500; - $status = $shows[1]; - $errorstring = $shows[2]; - } else { - for my $href (@shows) { - my %show; - $show{'start'} = $href->{'START'}->strftime("%FT%T"); - $show{'id'} = int($href->{'ID'}); - $show{'title'} = $href->{'TITLE'}; - $show{'len'} = int($href->{'LEN'}); - push @showlist, \%show; +my $q = CGI->new; +my $num_days = $q->param('DAYS'); +$num_days = 1 unless (defined $num_days); + +my $date = DateTime->today(); +my $start_date = $q->param('START'); +if(defined $start_date) { + my $strp = DateTime::Format::Strptime->new(pattern => '%F'); + $date = $strp->parse_datetime($start_date); +} + +if(!defined $date) { + $responsecode = 400; + $errorstring = "field START contains invalid date" +} if($num_days <= 0) { + $responsecode = 400; + $errorstring = "field DAYS must be > 0" +} else { + (my $ctx, $status, $errorstring) = RHRD::rddb::init(); + if(defined $ctx) { + for (my $i = 0; $i < $num_days; $i++) { + my @shows = RHRD::rddb::get_schedule_log($ctx, $date->year, $date->month, $date->day); + if(!defined $shows[0] && defined $shows[1]) { + $responsecode = 500; + $status = $shows[1]; + $errorstring = $shows[2]; + } else { + for my $href (@shows) { + my %show; + $show{'start'} = $href->{'START'}->iso8601(); + $show{'id'} = int($href->{'ID'}); + $show{'title'} = $href->{'TITLE'}; + $show{'len'} = int($href->{'LEN'}); + push @showlist, \%show; + } + $responsecode = 200; + $status = "OK"; + $errorstring = "success"; + } + $date += DateTime::Duration->new(days => 1); } - $responsecode = 200; - $status = "OK"; - $errorstring = "success"; + + RHRD::rddb::destroy($ctx); } - RHRD::rddb::destroy($ctx); } my %answer; |