summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-06-23 17:11:11 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-06-23 17:11:57 (GMT)
commit7b3101a41ffdbc164ff42cec4121d1d5738384b3 (patch)
tree31109c35b5834a06797687e11d3746d26a079148
parent31eac3225dc64688e70d08cfc2095bcc732a5fb0 (diff)
schedule exporter knows has parameters
-rw-r--r--README2
-rwxr-xr-xrh-bin/schedules.json68
2 files changed, 47 insertions, 23 deletions
diff --git a/README b/README
index dea1b07..0ee4f1f 100644
--- a/README
+++ b/README
@@ -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;