From a8ce2eafd79fac37b2c03a47b50e49d7d35b1a37 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Wed, 19 Jun 2024 13:47:16 +0200
Subject: democracy now: import into second cart of show log


diff --git a/rhautoimport-dn b/rhautoimport-dn
index 8c08551..144eff6 100755
--- a/rhautoimport-dn
+++ b/rhautoimport-dn
@@ -51,7 +51,6 @@ if($#ARGV >= 0 && $ARGV[0] eq 'last') {
 }
 rhautoimport::report_title_and_last($TITLE, $LAST_RUN);
 
-
 my @today = Date::Calc::Today();
 my @yesterday = Date::Calc::Add_Delta_Days(@today, -1);
 my @tomorrow = Date::Calc::Add_Delta_Days(@today, 1);
@@ -71,6 +70,7 @@ print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_day
 
 my $show_id = -1;
 my $show_title = "";
+my @show_carts = ();
 
 my @allowed_dbs = rhautoimport::get_dropboxes($RD_GROUP);
 if(!defined $allowed_dbs[0] && defined $allowed_dbs[1]) {
@@ -82,6 +82,7 @@ for my $href ( @allowed_dbs ) {
   if($dow == $href->{'SHOWDOW'}) {
     $show_title = $href->{'SHOWTITLE'};
     $show_id = $href->{'SHOWID'};
+    @show_carts = rhautoimport::get_show_carts($show_id);
     last;
   }
 }
@@ -90,6 +91,15 @@ if($show_id < 0) {
   print "no dropbox for day in question\n";
   exit 42;
 }
+if(!defined $show_carts[0] && defined $show_carts[1]) {
+  print "$show_carts[1]\n";
+  exit 1;
+}
+if(!defined $show_carts[1]) {
+  print "unable to select to second cart of the show\n";
+  exit 1;
+}
+my $import_cart = $show_carts[1];
 
 my $y = sprintf("%04d-%02d-%02d", @broadcast_day);
 my $yc = sprintf("%04d-%02d%02d", @broadcast_day);
@@ -168,10 +178,10 @@ for my $entry ($headlines_feed->entries) {
   }
 }
 
-print "\n\nwill import '$uri' to show $show_id, $show_title\n\n";
+print "\n\nwill import '$uri' to show $show_id (cart $import_cart), $show_title\n\n";
 
 my $exit_code = 0;
-my ($ret, $log) = rhautoimport::import_uri($show_id, $uri->as_string);
+my ($ret, $log) = rhautoimport::import_uri($show_id, $uri->as_string, undef, $import_cart);
 if($ret) {
   print "\nImport Error:\n\n";
   print $log;
diff --git a/rhautoimport.pm b/rhautoimport.pm
index 4e893ae..9ac48f0 100644
--- a/rhautoimport.pm
+++ b/rhautoimport.pm
@@ -70,6 +70,20 @@ sub get_dropboxes
   return @allowed_dbs;
 }
 
+sub get_show_carts
+{
+  my ($show_id) = @_;
+
+  my ($ctx, $status, $errorstring) = RHRD::rddb::init();
+  if(!defined $ctx) {
+    return ($ctx, $errorstring);
+  }
+  my @show_carts = RHRD::rddb::get_show_carts($ctx, $show_id);
+  RHRD::rddb::destroy($ctx);
+
+  return @show_carts;
+}
+
 sub fetch_parse_rss
 {
   my ($url, $ua_str, $headers, $queries) = @_;
-- 
cgit v0.10.2