summaryrefslogtreecommitdiff
path: root/rh-bin
diff options
context:
space:
mode:
Diffstat (limited to 'rh-bin')
-rwxr-xr-xrh-bin/schedules.json68
1 files changed, 46 insertions, 22 deletions
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;