summaryrefslogtreecommitdiff
path: root/rhimport-dn
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport-dn')
-rwxr-xr-xrhimport-dn28
1 files changed, 19 insertions, 9 deletions
diff --git a/rhimport-dn b/rhimport-dn
index 0b95049..ca7d4b2 100755
--- a/rhimport-dn
+++ b/rhimport-dn
@@ -40,6 +40,7 @@ my $DBUSER = "rivendell";
my $DBPW = "lldriven";
my $DB = "rivendell";
+my $STAT_FILE = $ENV{'HOME'} . "/rhimport-dn.stat";
my $RSS_URL = "http://www.democracynow.org/podcast.xml";
my @PV_SCRIPT = ('/usr/bin/ssh', 'root@intranet', 'addnote', '111');
@@ -89,8 +90,20 @@ for my $entry ($feed->entries) {
if($entry->id =~ /tag:democracynow.org,([0-9-]+):media\/mp3download\/[^\/]+/) {
next if($y ne $1);
-
+
my $ff = File::Fetch->new(uri => $entry->enclosure->url);
+
+ my $current_file = `cat $STAT_FILE`;
+ if($current_file eq $ff->output_file) {
+ print "Already downloaded file of today\n";
+ $dbh->disconnect();
+ exit 0;
+ }
+ unlink($STAT_FILE);
+ open(my $fhs, '>', $STAT_FILE);
+ print $fhs $ff->output_file;
+ close($fhs);
+
print $1 . ": downloading " . $entry->enclosure->url . " (" . $entry->enclosure->length . " Bytes) .. ";
$file = $ff->fetch( to => '/tmp' ) or die $ff->error;
print "ok\n";
@@ -105,16 +118,13 @@ for my $entry ($feed->entries) {
print $writer $sum_title . "\n" . $sum_text;
close $writer;
waitpid $pid, 0;
- my $out = join('', <$reader>);
- my $errstr = "";
if ( $? >> 8 ) {
- $errstr = join('', <$error>);
- print "PV: adding note failed";
- print "STDERR:\n" . $errstr . "\n\n";
- print "STDOUT:\n" . $out . "\n\n";
+ print "\n\nPV: adding note failed\n";
+ print "STDERR:\n" . join('', <$error>) . "\n";
+ print "STDOUT:\n" . join('', <$reader>) . "\n";
} else {
- print "PV: note added successfully";
- print $out . "\n";
+ print "\nPV: note added successfully";
+ print join('', <$reader>) . "\n";
}
}
print "\n";