diff options
Diffstat (limited to 'rhautoimport-gd')
-rwxr-xr-x | rhautoimport-gd | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/rhautoimport-gd b/rhautoimport-gd index d025025..99dc63b 100755 --- a/rhautoimport-gd +++ b/rhautoimport-gd @@ -23,6 +23,7 @@ use strict; use Date::Calc; +use DateTime::Format::Strptime; use XML::Feed; use XML::Feed::Entry; use XML::Feed::Content; @@ -40,6 +41,7 @@ my $RD_GROUP = "womenonair"; my $PV_ID = '210'; my $TITLE="Women on Air present: Globale Dialoge"; my $LAST_RUN = 0; +my $upload_delay_days = 1; # files are usually delayed at least one day binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); @@ -70,27 +72,32 @@ my $show_id_reb = $allowed_dbs[$idx_reb]->{'SHOWID'}; my $show_title_reb = $allowed_dbs[$idx_reb]->{'SHOWTITLE'}; -my @today = Date::Calc::Standard_to_Business(Date::Calc::Today()); -my $dow = $today[2]; +my @today = Date::Calc::Today(); +my @tmp = Date::Calc::Standard_to_Business(@today); +my $dow = $tmp[2]; if($dow > 1 && $dow < 5) { print "please don't run this script Tuesday, Wednesday or Thursday!\n"; exit 42; } -$today[2] = 2; -my @broadcast_day = Date::Calc::Business_to_Standard(@today); +$tmp[2] = 2; +my @broadcast_date = Date::Calc::Business_to_Standard(@tmp); if($dow == 1) { - @broadcast_day = Date::Calc::Add_Delta_Days(@broadcast_day, -7); + @broadcast_date = Date::Calc::Add_Delta_Days(@broadcast_date, -7); } -my @import_date = Date::Calc::Add_Delta_Days(@broadcast_day, 6); +my @import_date = Date::Calc::Add_Delta_Days(@broadcast_date, 6); my @import_date_reb = Date::Calc::Add_Delta_Days(@import_date, 3); -print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; +print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n"; print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; print "day of Radio Helsinki rebroadcast: " . Date::Calc::Date_to_Text(@import_date_reb) . "\n"; -my $bd = sprintf("%04d-%02d-%02d", @broadcast_day); -my $bdfile = sprintf("^%4d%02d%02d", @broadcast_day); +if(Date::Calc::Delta_Days(@broadcast_date, @today) <= $upload_delay_days) { + print "File won't be available by now!\n"; + exit 42; +} -print "looking for files like '$bdfile' in RSS Feed\n"; +my $bd = sprintf("%04d-%02d-%02d", @broadcast_date); + +print "looking for files with cba:broadcastDate $bd in RSS Feed\n"; print " -> $RSS_URL\n"; my ($result, $feed) = rhautoimport::fetch_parse_rss_cba($RSS_URL); @@ -108,6 +115,13 @@ my $i = 0; for my $entry ($feed->entries) { $i++; next unless $entry->enclosure; + + my $entry_bdt = $entry->{'entry'}{'https://cba.fro.at/help#feeds'}{'broadcastDate'}; + next unless (defined $entry_bdt); + my $bdt = DateTime::Format::Strptime::strptime("%a, %d %b %Y", $entry_bdt); + + next unless($broadcast_date[0] == $bdt->year && $broadcast_date[1] == $bdt->month && $broadcast_date[2] == $bdt->day); + my $j = 0; for my $enclosure($entry->enclosure) { $j++; @@ -121,10 +135,6 @@ for my $entry ($feed->entries) { $uri = new URI::URL($orig_uri); my @path = $uri->path_components; $file = $path[-1]; - unless($file =~ /$bdfile/) { - $uri = ""; - next; - } my $current_file = `cat $STAT_FILE`; if($current_file eq $file) { |