From b461ed0c74fa3a3cad68cabe4cc19f0298177c18 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Tue, 4 Sep 2012 16:16:51 +0000
Subject: added rebroadcast for radio attac


diff --git a/rhimport-ra b/rhimport-ra
index 1ee9a5a..bacfce4 100755
--- a/rhimport-ra
+++ b/rhimport-ra
@@ -55,21 +55,27 @@ my $group = "RadioATTAC";
 my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr";
 my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
 
-if(scalar(@allowed_dbs) != 1) {
-  print "found multiple or no Dropboxes for this group?!\n";
+my $idx = 0;
+my $idx_reb = 1;
+if(scalar(@allowed_dbs) != 2) {
+  print "found more or less than 2 Dropboxes for this group?!\n";
   $dbh->disconnect();
   exit 1;
 }
-my $dropbox = $allowed_dbs[0]->{'PATH'};
-my $to_cart = $allowed_dbs[0]->{'TO_CART'};
+my $dropbox = $allowed_dbs[$idx]->{'PATH'};
+my $to_cart = $allowed_dbs[$idx]->{'TO_CART'};
+my $dropbox_reb = $allowed_dbs[$idx_reb]->{'PATH'};
+my $to_cart_reb = $allowed_dbs[$idx_reb]->{'TO_CART'};
 
 my @today = Date::Calc::Standard_to_Business(Date::Calc::Today());
 $today[2] = 1;
 my @broadcast_day = Date::Calc::Business_to_Standard(@today);
 $today[2] = 4;
 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], 3);
 print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\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]);
 print "looking for files from $bd in RSS Feed\n";
@@ -105,6 +111,8 @@ for my $entry ($feed->entries) {
 
     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;
   }
@@ -115,6 +123,7 @@ if($file eq "" || !(-e "$file")) {
 }
 
 print "will import $file to dropbox $dropbox (cart=$to_cart)\n";
+print "will import $file to rebroadcast dropbox $dropbox_reb (cart=$to_cart_reb)\n\n";
 
 my $error_cb = sub {
   my ($text) = @_;
@@ -130,6 +139,10 @@ my $log = rhimport::clear_carts($dbh, $group, $to_cart);
 my $import_log;
 ($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
 $log .= $import_log;
+$import_log = rhimport::clear_carts($dbh, $group, $to_cart_reb);
+$log .= $import_log;
+($ret, $import_log) = rhimport::import_single($file, $dropbox_reb, $user, 0, $error_cb);
+$log .= $import_log;
 
 $dbh->disconnect();
 
-- 
cgit v0.10.2