summaryrefslogtreecommitdiff
path: root/rhimport-dn
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-07-22 11:23:01 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-07-22 11:23:01 (GMT)
commit6418c2c469db7df7f8a83990017b0c9e3020f359 (patch)
treea91f2c7b522e05c0b2b90538144a6304e2ae0818 /rhimport-dn
parentb44097e9249a69474b67540a27a58c8987607141 (diff)
added stat_file check to rhimport-dn
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";