summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/RHRD/rddb.pm37
-rwxr-xr-xlib/RHRD/utils.pm9
-rwxr-xr-xutils/rhrd-schedules26
3 files changed, 61 insertions, 11 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index f9bcb87..380a486 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -999,7 +999,7 @@ sub list_shows
}
my @show_dbs;
- while(my ($to_cart, $params, $lowcart, $highcart) = $sth->fetchrow_array()) {
+ while(my ($to_cart, $params) = $sth->fetchrow_array()) {
my @p = split(';', $params);
next if ('S' ne $p[0]);
@@ -1206,6 +1206,41 @@ sub get_show_title_and_log
return ($title, $log, 'OK', 'success');
}
+sub get_show_info
+{
+ my ($ctx, $showid) = @_;
+
+ my $sql = qq{select SET_USER_DEFINED from DROPBOXES where STATION_NAME = ? and TO_CART = ?;};
+
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $showid)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($params) = $sth->fetchrow_array;
+ $sth->finish();
+
+ my @p = split(';', $params);
+ return (undef, 'ERROR', "show with $showid does not exist") unless ('S' eq $p[0]);
+
+ my $entry = {};
+ $entry->{'ID'} = $showid;
+ my ($title, $log, $status, $errorstring) = get_show_title_and_log($ctx, $showid);
+ return (undef, $status, $errorstring) unless (defined $title && defined $log);
+
+ $entry->{'TITLE'} = $title;
+ $entry->{'LOG'} = $log;
+ $entry->{'RHYTHM'} = $p[1];
+ $entry->{'DOW'} = int $p[2];
+ $entry->{'DOW'} = 0 unless $entry->{'DOW'} < 7;
+ substr($p[3], 2, 0) = ':';
+ $entry->{'STARTTIME'} = $p[3];
+ $entry->{'LEN'} = int $p[4];
+
+ return ($entry, 'OK', 'success');
+}
+
sub get_show_carts
{
my ($ctx, $showid) = @_;
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm
index fbc3933..7f060e9 100755
--- a/lib/RHRD/utils.pm
+++ b/lib/RHRD/utils.pm
@@ -32,6 +32,7 @@ use JSON;
sub get_rd_week
{
+ my ($time) = @_;
#
# This computes the current Rivendell Week based on the number
# of weeks since epoch.
@@ -48,10 +49,12 @@ sub get_rd_week
# with 0 meaning Week 1. So add 1 to that number and you will get
# the current RD week.
#
- my $now = DateTime->now();
+ if(!defined($time)) {
+ $time = DateTime->now();
+ }
my $tz = DateTime::TimeZone->new(name => 'Europe/Vienna');
- my $tz_offset = $tz->offset_for_datetime($now);
- my $sEpoch = $now->epoch() + $tz_offset;
+ my $tz_offset = $tz->offset_for_datetime($time);
+ my $sEpoch = $time->epoch() + $tz_offset;
my $week = floor(((($sEpoch + 259200)/604800) + 2) % 4) + 1;
return $week;
diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules
index 3579821..6904154 100755
--- a/utils/rhrd-schedules
+++ b/utils/rhrd-schedules
@@ -27,6 +27,7 @@ use lib "../lib/";
use RHRD::rddb;
use RHRD::utils;
+use DateTime;
use Date::Calc;
sub print_usage
@@ -68,6 +69,7 @@ sub show__day
}
my $dow = Date::Calc::Day_of_Week(@date);
+ my $week = RHRD::utils::get_rd_week(DateTime->new(year => $date[0], month => $date[1], day => $date[2], hour => 12));
my $errcnt = 0;
for my $entry (@{$data}) {
@@ -80,16 +82,26 @@ sub show__day
print " $start: ($showid) -> ";
if($showid > 0) {
- my ($rdtitle, $rdlog, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($ctx, $showid);
- if(!defined $rdtitle || !defined $rdlog) {
+ my ($show, $status, $errorstring) = RHRD::rddb::get_show_info($ctx, $showid);
+ if(!defined $show) {
print "$status: $errorstring\n";
$errcnt++;
- } elsif ($title ne $rdtitle) {
- print "WARNING: title mismatch (PV: '$title' != RD: '$rdtitle')\n";
- $errcnt++;
} else {
- # TODO: check DayOfWeek!!!
- print "OK: $title\n";
+ my @weeks = split('', ${$show}{'RHYTHM'});
+ if ($title ne ${$show}{'TITLE'}) {
+ print "WARNING: title mismatch (PV: '$title' != RD: '" . ${$show}{'TITLE'} . "')\n";
+ $errcnt++;
+ } elsif ($dow != ${$show}{'DOW'}) {
+ print "WARNING: wrong day of week (PV: " . Date::Calc::Day_of_Week_to_Text($dow) . " != RD: " . Date::Calc::Day_of_Week_to_Text(${$show}{'DOW'}) . ")\n";
+ $errcnt++;
+ } elsif ($weeks[$week-1] != '1') {
+ print "WARNING: this is week $week but show rhythm is: " . ${$show}{'RHYTHM'} . " -> show shouldn't air in this week!\n";
+ $errcnt++;
+ } else {
+ # TODO: check for STARTTIME
+ # TODO: check for LEN (missing endtime in pv export...)
+ print "OK: $title\n";
+ }
}
} else {
print "ERROR: show '$pvid|$title' not configured\n";