summaryrefslogtreecommitdiff
path: root/rhimport-wl
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport-wl')
-rwxr-xr-xrhimport-wl28
1 files changed, 22 insertions, 6 deletions
diff --git a/rhimport-wl b/rhimport-wl
index 115ffd4..9844506 100755
--- a/rhimport-wl
+++ b/rhimport-wl
@@ -66,9 +66,26 @@ my $to_cart = $allowed_dbs[0]->{'TO_CART'};
my @today = Date::Calc::Today();
print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
-my $t = sprintf("%04d-%02d-%02d", $today[0], $today[1], $today[2]);
-my $tfile = sprintf("%04d%02d%02d.mp3", $today[0], $today[1], $today[2]);
-print "looking for files from today in RSS Feed\n";
+my @import_date;
+my $t;
+my $tfile;
+
+if(Date::Calc::Day_of_Week(@today) == 7) {
+ @import_date = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1);
+ $t = sprintf("%04d-%02d-%02d", $today[0], $today[1], $today[2]);
+ $tfile = sprintf("%04d%02d%02d.mp3", $today[0], $today[1], $today[2]);
+ print "looking for files from today in RSS Feed\n";
+} elsif(Date::Calc::Day_of_Week(@today) == 1) {
+ my @yesterday = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], -1);
+ @import_date = @today;
+ $t = sprintf("%04d-%02d-%02d", $yesterday[0], $yesterday[1], $yesterday[2]);
+ $tfile = sprintf("%04d%02d%02d.mp3", $yesterday[0], $yesterday[1], $yesterday[2]);
+ print "looking for files from yesterday in RSS Feed\n";
+} else {
+ print "it's neither Sunday nor Monday, please check cron script";
+ exit 1;
+}
+
my $feed = XML::Feed->parse(URI->new($RSS_URL))
or die "Error fetching feed: " . XML::Feed->errstr;
@@ -78,7 +95,7 @@ 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 $tfile); # file not from today
+ next if($ff->output_file ne $tfile); # file not from today/yesterday
my $sum_title = $entry->title;
my $sum_text = $entry->content->body;
@@ -97,8 +114,7 @@ for my $entry ($feed->entries) {
print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
- my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1);
- rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $tomorrow[0], $tomorrow[1], $tomorrow[2]));
+ rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]));
print "\n";
}
}