summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2012-02-17 18:42:44 (GMT)
committerChristian Pointner <equinox@helsinki.at>2012-02-17 18:42:44 (GMT)
commitfbaf2ab247a2d08214d3c293c1d77d1084eb9bcd (patch)
tree99e0f151a6e76ebf961fdfe2fe0071d2ab0380ab
parentbd0d8a26d9837b7bb71740856ebcb6df1a84d226 (diff)
look for files from last week if no one for this week (@radiostimme)
-rwxr-xr-xrhimport-rs80
1 files changed, 49 insertions, 31 deletions
diff --git a/rhimport-rs b/rhimport-rs
index 3d9d4f5..99d2ce3 100755
--- a/rhimport-rs
+++ b/rhimport-rs
@@ -79,50 +79,68 @@ $today[2] = 6;
my @import_date = Date::Calc::Business_to_Standard(@today);
my @import_date_reb = Date::Calc::Add_Delta_Days($import_date[0], $import_date[1], $import_date[2], 10);
print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n";
+my @broadcast_day_last_week = Date::Calc::Add_Delta_Days($broadcast_day[0], $broadcast_day[1], $broadcast_day[2], -7);
+print " or: " . Date::Calc::Date_to_Text(@broadcast_day_last_week) . "\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[0], $broadcast_day[1], $broadcast_day[2]);
-my $bdfile = sprintf("Rast%04d%02d%02dcba.mp3", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]);
-print "looking for files from $bd in RSS Feed\n";
+my $bdtw = sprintf("%04d-%02d-%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]);
+my $bdtwfile = sprintf("RAST%04d%02d%02dCBA.MP3", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]);
+my $bdlw = sprintf("%04d-%02d-%02d", $broadcast_day_last_week[0], $broadcast_day_last_week[1], $broadcast_day_last_week[2]);
+my $bdlwfile = sprintf("RAST%04d%02d%02dCBA.MP3", $broadcast_day_last_week[0], $broadcast_day_last_week[1], $broadcast_day_last_week[2]);
+print "looking for files from $bdtw or $bdlw in RSS Feed\n";
my $feed = XML::Feed->parse(URI->new($RSS_URL))
or die "Error fetching feed: " . XML::Feed->errstr;
my $file = "";
my $out_file = "";
-for my $entry ($feed->entries) {
- if($entry->enclosure && $entry->enclosure->type eq "audio/mpeg") {
- my $ff = File::Fetch->new(uri => $entry->enclosure->url);
- next if($ff->output_file ne $bdfile); # file not from correct day
-
- my $sum_title = $entry->title;
- my $sum_text = $entry->content->body;
-
- my $current_file = `cat $STAT_FILE`;
- if($current_file eq $ff->output_file) {
- print "Already downloaded file of today\n";
- $dbh->disconnect();
- exit 0;
- }
- $out_file = $ff->output_file;
-
- print $bdfile . ": downloading " . $entry->enclosure->url . " (" . $entry->enclosure->length . " Bytes) .. ";
- $file = $ff->fetch( to => '/tmp' ) or die $ff->error;
- print "ok\n";
-
- print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
-
- rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]), 1);
- print "\n";
- rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date_reb[0], $import_date_reb[1], $import_date_reb[2]), 2);
- print "\n";
- last;
+my $bd = $bdtw;
+my $bdfile = $bdtwfile;
+
+while(1) {
+ for my $entry ($feed->entries) {
+ if($entry->enclosure && $entry->enclosure->type eq "audio/mpeg") {
+ my $ff = File::Fetch->new(uri => $entry->enclosure->url);
+ next if(uc($ff->output_file) ne $bdfile); # file not from correct day
+
+ my $sum_title = $entry->title;
+ my $sum_text = $entry->content->body;
+
+ my $current_file = `cat $STAT_FILE`;
+ if($current_file eq $ff->output_file) {
+ print "Already downloaded file of today\n";
+ $dbh->disconnect();
+ exit 0;
+ }
+ $out_file = $ff->output_file;
+
+ print $bdfile . ": downloading " . $entry->enclosure->url . " (" . $entry->enclosure->length . " Bytes) .. ";
+ $file = $ff->fetch( to => '/tmp' ) or die $ff->error;
+ print "ok\n";
+
+ print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
+
+ rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]), 1);
+ print "\n";
+ rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date_reb[0], $import_date_reb[1], $import_date_reb[2]), 2);
+ print "\n";
+
+ last;
+ }
+ }
+ last if($file ne "");
+ if($bd eq $bdtw) {
+ print "No Entry found from $bdtw - trying $bdlw\n";
+ $bd = $bdlw;
+ $bdfile = $bdlwfile;
}
+ else { last; };
}
+
if($file eq "" || !(-e "$file")) {
- print "No Entry found from $bd or download error - will retry later\n";
+ print "No Entry found from $bdtw or $bdlw or download error - will retry later\n";
exit 1;
}