summaryrefslogtreecommitdiff
path: root/rhimport-dn
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport-dn')
-rwxr-xr-xrhimport-dn31
1 files changed, 19 insertions, 12 deletions
diff --git a/rhimport-dn b/rhimport-dn
index f9d2613..5a9fae0 100755
--- a/rhimport-dn
+++ b/rhimport-dn
@@ -24,6 +24,7 @@
use strict;
use DBI;
use Date::Calc;
+use Time::localtime;
use XML::Feed;
use XML::Feed::Entry;
use XML::Feed::Content;
@@ -62,13 +63,21 @@ my $to_cart = 0;
my @today = Date::Calc::Today();
my @yesterday = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], -1);
+my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1);
+
+my @broadcast_day = @yesterday;
+my @import_day = @today;
+if(localtime->hour >= 12) {
+ print "It's past noon, assuming to import file from today\n";
+ @broadcast_day = @today;
+ @import_day = @tomorrow;
+}
-print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
-print "yesterday: " . Date::Calc::Date_to_Text(@yesterday) . "\n";
-
+print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n";
+print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_day) . "\n";
for my $href ( @allowed_dbs ) {
- my $dow = Date::Calc::Day_of_Week(@today);
+ my $dow = Date::Calc::Day_of_Week(@import_day);
if ($dow == int(substr($href->{'NAME'},0,2))) {
$dropbox = $href->{'PATH'};
$to_cart = $href->{'TO_CART'};
@@ -76,13 +85,13 @@ for my $href ( @allowed_dbs ) {
}
if($dropbox eq "") {
- print "no dropbox for today\n";
+ print "no dropbox for day in question\n";
$dbh->disconnect();
exit 0;
}
-my $y = sprintf("%04d-%02d-%02d", $yesterday[0], $yesterday[1], $yesterday[2]);
-my $yc = sprintf("%04d-%02d%02d", $yesterday[0], $yesterday[1], $yesterday[2]);
+my $y = sprintf("%04d-%02d-%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]);
+my $yc = sprintf("%04d-%02d%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]);
print "looking for files from date $y in RSS Feed\n";
my $files_feed = XML::Feed->parse(URI->new($FILES_RSS_URL))
@@ -99,7 +108,7 @@ for my $entry ($files_feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
- print "Already downloaded file of today\n";
+ print "Already downloaded file of day in question\n";
$dbh->disconnect();
exit 0;
}
@@ -112,9 +121,7 @@ for my $entry ($files_feed->entries) {
}
}
if($file eq "" || !(-e "$file")) {
- print "No Entry found for today or download error - just clearing cart!\n";
- rhimport::check_key_file() or die "Import Key not found, use rhimport-create-id to create one\n";
- rhimport::clear_carts($dbh, $group, $to_cart);
+ print "No Entry found from day in qeustion or download error - will retry later\n";
exit 1;
}
@@ -132,7 +139,7 @@ for my $entry ($headlines_feed->entries) {
next if($y ne $1);
print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
- rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $today[0], $today[1], $today[2]), "1");
+ rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_day[0], $import_day[1], $import_day[2]), "1");
print "\n";
}
}