summaryrefslogtreecommitdiff
path: root/rhautoimport-xy
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-12-28 15:12:07 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-12-28 15:12:07 (GMT)
commit15241d289910aed8981bbe3975c996fa21b411b8 (patch)
tree62ce8fa84f9d165e32ff56cc4cb29f3c638fa6d6 /rhautoimport-xy
parent9b1feb183371db8e691ef6063553d1b04df332a0 (diff)
renewed x/xy importer
Diffstat (limited to 'rhautoimport-xy')
-rwxr-xr-xrhautoimport-xy62
1 files changed, 43 insertions, 19 deletions
diff --git a/rhautoimport-xy b/rhautoimport-xy
index b5e046c..36722c3 100755
--- a/rhautoimport-xy
+++ b/rhautoimport-xy
@@ -42,6 +42,7 @@ my $PV_ID = '608';
my $TITLE="X_XY (Un)gelöst und (Un)erhört!";
my $LAST_RUN = 0;
my $upload_delay_days = 1; # files are usally there at least 1 day after original broadcast
+my $last_resort_threshold = 2; # also consider older file when there are only 2 days until the RH broadcast
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
@@ -50,7 +51,7 @@ binmode(STDERR, ":utf8");
my $curweek = RHRD::utils::get_rd_week();
if($#ARGV >= 0 && $ARGV[0] eq 'last') {
- if($curweek == 2 || $curweek == 4) {
+ if($curweek == 4) {
print "!!!This is the last attempt, there won't be a retry on error!!!\n";
$LAST_RUN = 1;
}
@@ -76,32 +77,44 @@ my @today = Date::Calc::Today();
my @import_date = Date::Calc::Standard_to_Business(@today);
my $dow = $import_date[2];
@import_date = Date::Calc::Business_to_Standard($import_date[0], $import_date[1], 2);
-if($dow <= 2) {
- if($curweek == 1 || $curweek == 3) {
- @import_date = Date::Calc::Add_Delta_Days(@import_date, 7);
- }
-} else {
+if($curweek == 1) {
+ @import_date = Date::Calc::Add_Delta_Days(@import_date, 21);
+} elsif ($curweek == 2) {
+ @import_date = Date::Calc::Add_Delta_Days(@import_date, 14);
+} elsif ($curweek == 3) {
@import_date = Date::Calc::Add_Delta_Days(@import_date, 7);
- if($curweek == 2 || $curweek == 4) {
- @import_date = Date::Calc::Add_Delta_Days(@import_date, 7);
- }
+} elsif($dow > 2) {
+ @import_date = Date::Calc::Add_Delta_Days(@import_date, 28);
}
-my @broadcast_date = Date::Calc::Add_Delta_Days(@import_date, -11);
+my @broadcast_dateW2 = Date::Calc::Add_Delta_Days(@import_date, -11);
print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
print "day of next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n";
-print "day of latest original broadcast before next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n";
+print "day of latest original broadcast before next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@broadcast_dateW2) . "\n";
-if(Date::Calc::Delta_Days(@broadcast_date, @today) <= $upload_delay_days) {
+if(Date::Calc::Delta_Days(@broadcast_dateW2, @today) <= $upload_delay_days) {
print "File won't be available by now!\n";
exit 42;
}
+my $includeW4 = 0;
+my @broadcast_dateW4 = Date::Calc::Add_Delta_Days(@broadcast_dateW2, -14);
+if(Date::Calc::Delta_Days(@import_date, @today) <= $last_resort_threshold) {
+ $includeW4 = 1;
+ print " ... it's already late, also including show from: " . Date::Calc::Date_to_Text(@broadcast_dateW4) . "\n";
+}
+
my $id = sprintf("%04d-%02d-%02d", @import_date);
-my $bd = sprintf("%04d-%02d-%02d", @broadcast_date);
-my $bdfile = sprintf("^0?%d-?0?%d-?%04d", $broadcast_date[2], $broadcast_date[1], $broadcast_date[0]);
+my $bdW2 = sprintf("%04d-%02d-%02d", @broadcast_dateW2);
+my $bdW4 = sprintf("%04d-%02d-%02d", @broadcast_dateW4);
+my $bdfileW2 = sprintf("^0?%d-?0?%d-?%04d", $broadcast_dateW2[2], $broadcast_dateW2[1], $broadcast_dateW2[0]);
+my $bdfileW4 = sprintf("^0?%d-?0?%d-?%04d", $broadcast_dateW4[2], $broadcast_dateW4[1], $broadcast_dateW4[0]);
-print "looking for files like '$bdfile' in RSS Feed\n";
+if($includeW4) {
+ print "looking for files like '$bdfileW2' and '$bdfileW4' in RSS Feed\n";
+} else {
+ print "looking for files like '$bdfileW2' in RSS Feed\n";
+}
print " -> $RSS_URL\n";
my ($result, $feed) = rhautoimport::fetch_parse_rss_cba($RSS_URL);
@@ -132,9 +145,16 @@ for my $entry ($feed->entries) {
$uri = new URI::URL($orig_uri);
my @path = $uri->path_components;
$file = $path[-1];
- unless(uc($file) =~ $bdfile) { # file not from correct day
- $uri = "";
- next;
+ unless(uc($file) =~ $bdfileW2) { # file not from correct day
+ if($includeW4) {
+ unless(uc($file) =~ $bdfileW4) { # file not from correct day (either from the show 2 weeks earlier
+ $uri = "";
+ next;
+ }
+ } else {
+ $uri = "";
+ next;
+ }
}
my $current_file = `cat $STAT_FILE`;
@@ -157,7 +177,11 @@ for my $entry ($feed->entries) {
last if $uri ne "";
}
if($uri eq "") {
- print "No Entry found from $bd - ";
+ if($includeW4) {
+ print "No Entry found from $bdW2 or $bdW4 - ";
+ } else {
+ print "No Entry found from $bdW2 - ";
+ }
if($LAST_RUN) {
print "giving up, manual import necessary!!!\n";
print "\n\n --> https://import.helsinki.at/shows/$show_id\n";