From 5c15154a15840173ca8167bb0bbb3db32290ce41 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Fri, 20 Jan 2012 22:54:46 +0000
Subject: moved pv add note to rhimport modul


diff --git a/rhimport-dn b/rhimport-dn
index b228bf0..d712c9b 100755
--- a/rhimport-dn
+++ b/rhimport-dn
@@ -134,25 +134,7 @@ for my $entry ($headlines_feed->entries) {
       print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
 
       push(@PV_SCRIPT, sprintf("%04d-%02d-%02d", $today[0], $today[1], $today[2]));
-      my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
-      $writer->autoflush(1);
-      local $SIG{CHLD} = 'DEFAULT';
-      my $pid = open3($writer, $reader, $error, @PV_SCRIPT);
-      binmode($reader, ":utf8");
-      binmode($writer, ":utf8");
-      binmode($error, ":utf8");
-      print $writer $sum_title . "\n" . $sum_text;
-      close $writer;
-      waitpid $pid, 0;
-      if ( $? >> 8 ) {
-        print "\n\nPV: adding note returned non-zero value\n";
-        print "STDERR:\n" . join('', <$error>) . "\n";
-        print "STDOUT:\n" . join('', <$reader>) . "\n";
-        print "Ignoring failed headline import!\n";
-      } else {
-        print join('', <$reader>) . "\n";
-        print join('', <$error>) . "\n";
-      }
+      rhimport::pv_add_note($sum_title, $sum_text, @PV_SCRIPT);
       print "\n";
     }
   }
diff --git a/rhimport-rs b/rhimport-rs
index 276d612..13ea5a3 100755
--- a/rhimport-rs
+++ b/rhimport-rs
@@ -115,47 +115,11 @@ for my $entry ($feed->entries) {
     print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n";
 
     push(@PV_SCRIPT, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]));
-    my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
-    $writer->autoflush(1);
-    local $SIG{CHLD} = 'DEFAULT';
-    my $pid = open3($writer, $reader, $error, @PV_SCRIPT);
-    binmode($reader, ":utf8");
-    binmode($writer, ":utf8");
-    binmode($error, ":utf8");
-    print $writer $sum_title . "\n" . $sum_text;
-    close $writer;
-    waitpid $pid, 0;
-    if ( $? >> 8 ) {
-      print "\n\nPV: adding note returned non-zero value\n";
-      print "STDERR:\n" . join('', <$error>) . "\n";
-      print "STDOUT:\n" . join('', <$reader>) . "\n";
-      print "Ignoring failed headline import!\n";
-    } else {
-      print join('', <$reader>) . "\n";
-      print join('', <$error>) . "\n";
-    }
+    rhimport::pv_add_note($sum_title, $sum_text, @PV_SCRIPT);
     print "\n";
 
     push(@PV_SCRIPT_REB, sprintf("%04d-%02d-%02d", $import_date_reb[0], $import_date_reb[1], $import_date_reb[2]));
-    ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
-    $writer->autoflush(1);
-    local $SIG{CHLD} = 'DEFAULT';
-    $pid = open3($writer, $reader, $error, @PV_SCRIPT_REB);
-    binmode($reader, ":utf8");
-    binmode($writer, ":utf8");
-    binmode($error, ":utf8");
-    print $writer $sum_title . "\n" . $sum_text;
-    close $writer;
-    waitpid $pid, 0;
-    if ( $? >> 8 ) {
-      print "\n\nPV: adding note returned non-zero value\n";
-      print "STDERR:\n" . join('', <$error>) . "\n";
-      print "STDOUT:\n" . join('', <$reader>) . "\n";
-      print "Ignoring failed headline import!\n";
-    } else {
-      print join('', <$reader>) . "\n";
-      print join('', <$error>) . "\n";
-    }
+    rhimport::pv_add_note($sum_title, $sum_text, @PV_SCRIPT_REB);
     print "\n";
 
     last;
diff --git a/rhimport-wl b/rhimport-wl
index cf51b73..6c2d314 100755
--- a/rhimport-wl
+++ b/rhimport-wl
@@ -100,25 +100,7 @@ for my $entry ($feed->entries) {
     
     my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1);
     push(@PV_SCRIPT, sprintf("%04d-%02d-%02d", $tomorrow[0], $tomorrow[1], $tomorrow[2]));
-    my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
-    $writer->autoflush(1);
-    local $SIG{CHLD} = 'DEFAULT';
-    my $pid = open3($writer, $reader, $error, @PV_SCRIPT);
-    binmode($reader, ":utf8");
-    binmode($writer, ":utf8");
-    binmode($error, ":utf8");
-    print $writer $sum_title . "\n" . $sum_text;
-    close $writer;
-    waitpid $pid, 0;
-    if ( $? >> 8 ) {
-      print "\n\nPV: adding note returned non-zero value\n";
-      print "STDERR:\n" . join('', <$error>) . "\n";
-      print "STDOUT:\n" . join('', <$reader>) . "\n";
-      print "Ignoring failed headline import!\n";
-    } else {
-      print join('', <$reader>) . "\n";
-      print join('', <$error>) . "\n";
-    }
+    rhimport::pv_add_note($sum_title, $sum_text, @PV_SCRIPT);
     print "\n";
   }
 }
diff --git a/rhimport.pm b/rhimport.pm
index d44c34b..6e125d2 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -327,4 +327,31 @@ sub delete_file
   return 1;
 }
 
+sub pv_add_note
+{
+  my $title = shift;
+  my $text = shift;
+  my @script = @_;
+
+  my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
+  $writer->autoflush(1);
+  local $SIG{CHLD} = 'DEFAULT';
+  my $pid = open3($writer, $reader, $error, @script);
+  binmode($reader, ":utf8");
+  binmode($writer, ":utf8");
+  binmode($error, ":utf8");
+  print $writer $title . "\n" . $text;
+  close $writer;
+  waitpid $pid, 0;
+  if ( $? >> 8 ) {
+    print "\n\nPV: adding note returned non-zero value\n";
+    print "STDERR:\n" . join('', <$error>) . "\n";
+    print "STDOUT:\n" . join('', <$reader>) . "\n";
+    print "Ignoring failed headline import!\n";
+  } else {
+    print join('', <$reader>) . "\n";
+    print join('', <$error>) . "\n";
+  }
+}
+
 1;
-- 
cgit v0.10.2