summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-24 19:01:55 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-24 19:01:55 (GMT)
commit6761a44cfb25af3f923a53375f05e75e8570403d (patch)
tree5bb59562bae08a0edf8ea71c62d89f635b6213a7
parentd9df4264e66e6091538ab24c41fad20131526460 (diff)
switch to use systemwide RHRD perl module
-rwxr-xr-xrhimport19
-rwxr-xr-xrhimport-btl17
-rwxr-xr-xrhimport-dn18
-rwxr-xr-xrhimport-fe19
-rwxr-xr-xrhimport-fw19
-rwxr-xr-xrhimport-mz16
-rwxr-xr-xrhimport-nw17
-rwxr-xr-xrhimport-o94n17
-rwxr-xr-xrhimport-oi17
-rwxr-xr-xrhimport-ra17
-rwxr-xr-xrhimport-rs19
-rwxr-xr-xrhimport-sm21
-rwxr-xr-xrhimport-sv21
-rwxr-xr-xrhimport-tr19
-rwxr-xr-xrhimport-ut17
-rwxr-xr-xrhimport-zf17
-rwxr-xr-xrhimport-zfw17
-rw-r--r--rhimport.pm168
18 files changed, 194 insertions, 281 deletions
diff --git a/rhimport b/rhimport
index ba40b9a..f0be9df 100755
--- a/rhimport
+++ b/rhimport
@@ -23,6 +23,7 @@
use strict;
use Getopt::Long;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -55,14 +56,14 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
$user = 'heslinki';
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-(my @allowed_dbs, $errorstring) = rhimport::get_dropboxes($dbh, $user);
-unless(defined $allowed_dbs[0]) {
- print "$allowed_dbs[1]\n";
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
exit 1;
}
@@ -71,15 +72,15 @@ if($LISTALLOWED) {
print "+-------+-------------------------------------------------------------------\n";
for my $href ( @allowed_dbs ) {
if($href->{'TYPE'} eq 'show') {
- my @show_carts = rhimport::get_show_carts($dbh, $href->{'SHOWLOG'}, $href->{'GROUPLOWCART'}, $href->{'GROUPHIGHCART'});
- unless(defined $show_carts[0]) {
- print "$show_carts[1]\n";
+ my @show_carts = RHRD::rddb::get_show_carts($dbh, $href->{'SHOWLOG'}, $href->{'GROUPLOWCART'}, $href->{'GROUPHIGHCART'});
+ if(!defined $show_carts[0] && defined $show_carts[2]) {
+ print "$show_carts[2]\n";
exit 1;
}
print "| $href->{'SHOWID'} | $href->{'SHOWTITLE'}, Carts: [" . join(', ', @show_carts) . "]\n";
}
}
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -116,7 +117,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($FILE, $DROPBOX, $user, 0, $cl_error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
if(!$ret) {
exit 1;
diff --git a/rhimport-btl b/rhimport-btl
index 7bb6527..b7e841f 100755
--- a/rhimport-btl
+++ b/rhimport-btl
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use LWP::Simple;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,16 +53,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "betweenlin";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than one Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -106,13 +111,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -154,7 +159,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-dn b/rhimport-dn
index d1fe3e1..8362f4b 100755
--- a/rhimport-dn
+++ b/rhimport-dn
@@ -31,6 +31,7 @@ use XML::Feed::Enclosure;
use URI::URL;
use IO::Handle;
use IPC::Open3;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -58,13 +59,16 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "democracyn";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
-
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $dropbox = "";
my $to_cart = 0;
@@ -94,7 +98,7 @@ for my $href ( @allowed_dbs ) {
if($dropbox eq "") {
print "no dropbox for day in question\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -120,13 +124,13 @@ for my $entry ($files_feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $path[-1]) {
print "Already downloaded file of day in question\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $path[-1];
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -217,7 +221,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-fe b/rhimport-fe
index e51de4a..c396f18 100755
--- a/rhimport-fe
+++ b/rhimport-fe
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use File::Touch;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -78,23 +79,27 @@ $group .= "Mi" if($dow == 3);
$group .= "Do" if($dow == 4);
$group .= "Fr" if($dow == 5);
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $dropbox = "";
my $to_cart = 0;
if(scalar(@allowed_dbs) == 0) {
print "no dropbox for day in question\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than one Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
$dropbox = $allowed_dbs[0]->{'PATH'};
@@ -121,13 +126,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -180,7 +185,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-fw b/rhimport-fw
index 148ed18..ef8b159 100755
--- a/rhimport-fw
+++ b/rhimport-fw
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -53,18 +54,22 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "freiewelle";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $idx = 0;
my $idx_reb = 1;
if(scalar(@allowed_dbs) != 2) {
print "found more or less than 2 Dropboxes for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[$idx]->{'PATH'};
@@ -93,7 +98,7 @@ my $current_stat = `cat $STAT_FILE`;
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id) {
print "Already downloaded current file\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -132,13 +137,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded current file\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -191,7 +196,7 @@ $log .= $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox_reb, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-mz b/rhimport-mz
index 57a3805..29b355a 100755
--- a/rhimport-mz
+++ b/rhimport-mz
@@ -28,6 +28,7 @@ use Time::localtime;
use IO::Handle;
use IPC::Open3;
use File::Slurp;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -79,15 +80,20 @@ switch($dow) {
else { print("invalid day of week?!\n"); exit 1; }
}
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
+
if(scalar(@allowed_dbs) != 1) {
print "found no or more than one Dropboxes for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -97,7 +103,7 @@ my $import_date = sprintf("%04d-%02d-%02d", @import_day);
my $current_date = `cat $STAT_FILE`;
if($current_date eq $import_date) {
print "Already downloaded file of day in question\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -218,7 +224,7 @@ foreach my $file (@files) {
$cart++;
}
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
if(!$ret) {
print "\nImport Error:\n";
diff --git a/rhimport-nw b/rhimport-nw
index 7d90c0b..8adea51 100755
--- a/rhimport-nw
+++ b/rhimport-nw
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,16 +53,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "netwatcher";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than 1 Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -115,13 +120,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -167,7 +172,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-o94n b/rhimport-o94n
index f54fce1..2f1fcec 100755
--- a/rhimport-o94n
+++ b/rhimport-o94n
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,12 +53,16 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "o94";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $dropbox = '';
@@ -72,7 +77,7 @@ for my $db (@allowed_dbs) {
}
if($to_cart == 0) {
print "no dropbox found for Tuesday?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -134,13 +139,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -186,7 +191,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-oi b/rhimport-oi
index b7c3635..7b33422 100755
--- a/rhimport-oi
+++ b/rhimport-oi
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,16 +53,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "ondainfo";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than one Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -88,7 +93,7 @@ my $current_stat = `cat $STAT_FILE`;
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id) {
print "Already downloaded current file\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -112,7 +117,7 @@ for my $entry ($feed->entries) {
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -154,7 +159,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-ra b/rhimport-ra
index 31ecdaf..0063338 100755
--- a/rhimport-ra
+++ b/rhimport-ra
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,18 +53,22 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "RadioATTAC";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $idx = 0;
my $idx_reb = 1;
if(scalar(@allowed_dbs) != 2) {
print "found more or less than 2 Dropboxes for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[$idx]->{'PATH'};
@@ -117,13 +122,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -176,7 +181,7 @@ $log .= $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox_reb, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-rs b/rhimport-rs
index f5bce9b..808d36c 100755
--- a/rhimport-rs
+++ b/rhimport-rs
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use LWP::Simple;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -54,12 +55,16 @@ $user =~ s/\n//;
my $group = "radioStimm";
my %week_table = ( 1 => 2, 2 => 6, 3 => 2, 4 => 6 );
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $dropbox = "";
my $to_cart = 0;
@@ -71,7 +76,7 @@ foreach(@allowed_dbs) {
}
if(!$to_cart) {
print "no dropbox found!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -111,7 +116,7 @@ print "day of latest original broadcast before next Radio Helsinki broadcast: "
if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) {
print "File won't be available by now!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -151,13 +156,13 @@ for my $entry ($feed->entries) {
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id && $current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -203,7 +208,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-sm b/rhimport-sm
index 9c3f475..252d72e 100755
--- a/rhimport-sm
+++ b/rhimport-sm
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use LWP::Simple;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -53,16 +54,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "soundsmove";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than one Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -76,7 +81,7 @@ if(($curweek != 1 && $curweek != 4) ||
($curweek == 1 && $dow > 3) ||
($curweek == 4 && $dow <= 3)) {
print "File won't be available by now!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
@@ -98,7 +103,7 @@ print "day of latest original broadcast before next Radio Helsinki broadcast: "
if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) {
print "File won't be available by now!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -138,13 +143,13 @@ for my $entry ($feed->entries) {
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id && $current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -190,7 +195,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-sv b/rhimport-sv
index 0998e67..840ff20 100755
--- a/rhimport-sv
+++ b/rhimport-sv
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use LWP::Simple;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -53,16 +54,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "svetjevas";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found more or less than one Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -75,7 +80,7 @@ my $dow = Date::Calc::Day_of_Week(@today);
if(($curweek != 3 && $curweek != 4) ||
($curweek == 4 && $dow > 2)) {
print "File won't be available by now!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
@@ -97,7 +102,7 @@ print "day of latest original broadcast before next Radio Helsinki broadcast: "
if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) {
print "File won't be available by now!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -137,13 +142,13 @@ for my $entry ($feed->entries) {
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id && $current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -189,7 +194,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-tr b/rhimport-tr
index b76f4bd..6551780 100755
--- a/rhimport-tr
+++ b/rhimport-tr
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,17 +53,21 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "tierrecht";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $idx = 0;
if(scalar(@allowed_dbs) != 1) {
print "found more or less than 1 Dropbox for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[$idx]->{'PATH'};
@@ -71,7 +76,7 @@ my $to_cart = $allowed_dbs[$idx]->{'TO_CART'};
my @today = Date::Calc::Standard_to_Business(Date::Calc::Today());
if($today[2] == 5) {
print "please don't run this script on fridays!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my @broadcast_day = Date::Calc::Business_to_Standard($today[0], $today[1], 5);
@@ -117,13 +122,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -169,7 +174,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-ut b/rhimport-ut
index 9941781..8edb30b 100755
--- a/rhimport-ut
+++ b/rhimport-ut
@@ -31,6 +31,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -52,18 +53,22 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "uton";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $idx = 0;
my $idx_reb = 1;
if(scalar(@allowed_dbs) != 2) {
print "found more or less than 2 Dropboxes for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[$idx]->{'PATH'};
@@ -117,13 +122,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -176,7 +181,7 @@ $log .= $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox_reb, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-zf b/rhimport-zf
index 506e163..0f28ed7 100755
--- a/rhimport-zf
+++ b/rhimport-zf
@@ -32,6 +32,7 @@ use IO::Handle;
use IPC::Open3;
use HTML::Entities;
use File::Touch;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -54,12 +55,16 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "zipfm";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
my $dropbox = "";
@@ -85,7 +90,7 @@ for my $href ( @allowed_dbs ) {
if($dropbox eq "") {
print "no dropbox for day in question\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
@@ -109,13 +114,13 @@ for my $entry ($feed->entries) {
my $current_file = `cat $STAT_FILE`;
if($current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -169,7 +174,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport-zfw b/rhimport-zfw
index 5a534bf..a04e249 100755
--- a/rhimport-zfw
+++ b/rhimport-zfw
@@ -32,6 +32,7 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
+use RHRD::rddb;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -53,16 +54,20 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "zipfmwla";
-my ($dbh, $errorstring) = rhimport::opendb();
+my ($dbh, $errorstring) = RHRD::rddb::opendb();
if(!defined $dbh) {
print "$errorstring\n";
exit 1;
}
-my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
+my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group);
+if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) {
+ print "$allowed_dbs[2]\n";
+ exit 1;
+}
if(scalar(@allowed_dbs) != 1) {
print "found no or more than one Dropboxes for this group?!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
my $dropbox = $allowed_dbs[0]->{'PATH'};
@@ -120,13 +125,13 @@ for my $entry ($feed->entries) {
my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/;
if($current_id eq $id && $current_file eq $ff->output_file) {
print "Already downloaded file of today\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 0;
}
$out_file = $ff->output_file;
if(!rhimport::check_file_extension($out_file)) {
print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n";
- rhimport::closedb($dbh);
+ RHRD::rddb::closedb($dbh);
exit 1;
}
@@ -172,7 +177,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-rhimport::closedb($dbh);
+RHRD::rddb::closedb($dbh);
unlink $file;
diff --git a/rhimport.pm b/rhimport.pm
index 3cdcf62..353b75d 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -35,8 +35,6 @@ use DateTime;
use DateTime::TimeZone;
use LWP::Simple;
use XML::Feed;
-use DBI;
-use Config::IniFiles;
my $ssh_host = "airplay";
my $ssh_user = "rhimport";
@@ -91,172 +89,6 @@ sub fetch_parse_rss
return XML::Feed->parse(\$xml);
}
-sub opendb
-{
- my $RD_CONF = "/etc/rd.conf";
- my $cfg = Config::IniFiles->new(-file => $RD_CONF)
- or return (undef, "Config File Error: " . join("\n", @Config::IniFiles::errors));
-
- my $dbhost = $cfg->val('mySQL', 'Hostname');
- my $dbname = $cfg->val('mySQL', 'Database');
- my $dbuser = $cfg->val('mySQL', 'Loginname');
- my $dbpasswd = $cfg->val('mySQL', 'Password');
-
- my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd")
- or return (undef, "Database Error: " . $DBI::errstr);
-
- $dbh->do(qq{SET CHARACTER SET utf8;})
- or return (undef, "Database Error: " . $dbh->errstr);
-
- return ($dbh);
-}
-
-sub closedb
-{
- my $dbh = shift;
- $dbh->disconnect();
-}
-
-sub get_token
-{
- my ($dbh, $username) = @_;
-
- my $sql = qq{select PASSWORD from USERS where LOGIN_NAME = ?;};
- my $sth = $dbh->prepare($sql)
- or return (undef, "Database Error: " . $dbh->errstr);
-
- $sth->execute($username)
- or return (undef, "Database Error: " . $sth->errstr);
-
- my ($token) = $sth->fetchrow_array;
- $sth->finish();
-
- unless(defined $token) {
- return (undef, "user '" . $username . "' not known by rivendell")
- }
- return ($token, 'OK', 'success');
-}
-
-
-sub get_showtitle_and_log
-{
- my ($dbh, $showid) = @_;
-
- my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;};
- my $sth = $dbh->prepare($sql)
- or return (undef, undef, "Database Error: " . $dbh->errstr);
-
- $sth->execute($showid)
- or return (undef, undef, "Database Error: " . $sth->errstr);
-
- my ($title, $macros) = $sth->fetchrow_array;
- $sth->finish();
-
- unless(defined $title) {
- return (undef, undef, "Show with ID=" . $showid . " not found!")
- }
- unless(defined $macros) {
- return (undef, undef, "Show with ID=" . $showid . " has no macro!");
- }
-
- unless($macros =~ /^LL 1 ([^ ]+) 0\!$/) {
- return (undef, undef, "Show with ID=" . $showid . " has invalid macro: '" . $macros . "'");
- }
- my $log = $1;
-
- return ($title, $log);
-}
-
-sub get_dropboxes
-{
- my ($dbh, $username) = @_;
-
- my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=?;};
-
- my $sth = $dbh->prepare($sql)
- or return (undef, "Database Error: " . $dbh->errstr);
-
- $sth->execute($username, 'import-dropbox') # TODO: hardcoded value
- or return (undef, "Database Error: " . $sth->errstr);
-
- my @allowed_dbs;
- while(my ($group, $to_cart, $normlevel, $trimlevel, $params, $lowcart, $highcart, $groupdesc) = $sth->fetchrow_array()) {
- my @p = split(';', $params);
-
- next unless($p[0] eq "S");
-
- my $entry = {};
- $entry->{'GROUP'} = $group;
- $entry->{'GROUPDESC'} = $groupdesc;
- $entry->{'GROUPLOWCART'} = int $lowcart;
- $entry->{'GROUPHIGHCART'} = int $highcart;
- $entry->{'NORMLEVEL'} = int $normlevel;
- $entry->{'TRIMLEVEL'} = int $trimlevel;
- $entry->{'PARAM'} = $params;
- $entry->{'TYPE'} = 'show';
- $entry->{'SHOWID'} = $to_cart;
-
- my ($title, $log, $status, $errorstring) = get_showtitle_and_log($dbh, $to_cart);
- unless (defined $title && defined $log) {
- return (undef, $status, $errorstring);
- }
- $entry->{'SHOWTITLE'} = $title;
- $entry->{'SHOWLOG'} = $log;
-
- $entry->{'SHOWRHYTHM'} = $p[1];
- $entry->{'SHOWDOW'} = int $p[2];
- $entry->{'SHOWDOW'} = 0 unless $entry->{'SHOWDOW'} < 7;
- substr($p[3], 2, 0) = ':';
- $entry->{'SHOWSTARTTIME'} = $p[3];
- $entry->{'SHOWLEN'} = int $p[4];
-
- push @allowed_dbs, $entry;
- }
- $sth->finish();
-
- return @allowed_dbs;
-}
-
-sub get_show_carts
-{
- my ($dbh, $logname, $group_low_cart, $group_high_cart) = @_;
-
- my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;};
- my $sth = $dbh->prepare($sql)
- or return (undef, "Database Error: " . $dbh->errstr);
-
- $sth->execute($logname)
- or return (undef, "Database Error: " . $sth->errstr);
-
- my $log_exists = $sth->fetchrow_array;
- $sth->finish();
-
- if(!defined $log_exists && $log_exists eq 'Y') {
- return (undef, "log $logname does not exist")
- }
-
- $logname=~s/ /_/g;
- $logname = $dbh->quote_identifier($logname . '_LOG');
- $sql = qq{select COUNT,CART_NUMBER from $logname order by COUNT;};
-
- $sth = $dbh->prepare($sql)
- or return (undef, "Database Error: " . $dbh->errstr);
-
- $sth->execute()
- or return (undef, "Database Error: " . $sth->errstr);
-
- my @carts;
- while(my ($count, $cart) = $sth->fetchrow_array()) {
- if($cart >= $group_low_cart && $cart <= $group_high_cart) {
- push @carts, $cart;
- }
- }
- $sth->finish();
-
- return @carts;
-}
-
-
sub clear_carts
{
my ($dbh, $group, $to_cart, $progress_cb) = @_;