summaryrefslogtreecommitdiff
path: root/rhimport-zf
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport-zf')
-rwxr-xr-xrhimport-zf20
1 files changed, 9 insertions, 11 deletions
diff --git a/rhimport-zf b/rhimport-zf
index c780540..c4b9365 100755
--- a/rhimport-zf
+++ b/rhimport-zf
@@ -22,7 +22,6 @@
#
use strict;
-use DBI;
use Date::Calc;
use XML::Feed;
use XML::Feed::Entry;
@@ -37,11 +36,6 @@ use File::Touch;
use lib '/usr/local/share/rhimport/';
use rhimport;
-my $DBHOST = "airplay";
-my $DBUSER = "rivendell";
-my $DBPW = "lldriven";
-my $DB = "rivendell";
-
my $STAT_FILE = $ENV{'HOME'} . "/rhimport-zf.stat";
my $NOTE_FILE = $ENV{'HOME'} . "/rhimport-zf.last_note";
my $NEW_FILE = $ENV{'HOME'} . "/rhimport-zf.is_new";
@@ -60,7 +54,11 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $group = "zipfm";
-my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr";
+my ($dbh, $errorstring) = rhimport::opendb();
+if(!defined $dbh) {
+ print "$errorstring\n";
+ exit 1;
+}
my @allowed_dbs = rhimport::get_dropboxes($dbh, $user, $group);
@@ -87,7 +85,7 @@ for my $href ( @allowed_dbs ) {
if($dropbox eq "") {
print "no dropbox for day in question\n";
- $dbh->disconnect();
+ rhimport::closedb($dbh);
exit 0;
}
@@ -111,13 +109,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";
- $dbh->disconnect();
+ rhimport::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";
- $dbh->disconnect();
+ rhimport::closedb($dbh);
exit 1;
}
@@ -171,7 +169,7 @@ my $import_log;
($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, 0, $error_cb);
$log .= $import_log;
-$dbh->disconnect();
+rhimport::closedb($dbh);
unlink $file;