summaryrefslogtreecommitdiff
path: root/rhimport-rs
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-22 13:34:05 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-22 13:34:05 (GMT)
commit6fb972eec6953a40d57b76b7894952abdc4437d2 (patch)
tree8d0f567c0d366327ffd5a7939646ea398be549d2 /rhimport-rs
parente6035cca7cf6f23b3965f6238e41103838c48d3b (diff)
refactoring
Diffstat (limited to 'rhimport-rs')
-rwxr-xr-xrhimport-rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/rhimport-rs b/rhimport-rs
index d0d7337..f2ca868 100755
--- a/rhimport-rs
+++ b/rhimport-rs
@@ -22,7 +22,6 @@
#
use strict;
-use DBI;
use Date::Calc;
use XML::Feed;
use XML::Feed::Entry;
@@ -37,11 +36,6 @@ use LWP::Simple;
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-rs.stat";
my $RSS_URL = "http://cba.fro.at/seriesrss/262433?c=Kfs2IoV2Wmd";
$XML::Feed::MULTIPLE_ENCLOSURES=1;
@@ -60,7 +54,11 @@ $user =~ s/\n//;
my $group = "radioStimm";
my %week_table = ( 1 => 2, 2 => 6, 3 => 2, 4 => 6 );
-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);
my $dropbox = "";
@@ -73,7 +71,7 @@ foreach(@allowed_dbs) {
}
if(!$to_cart) {
print "no dropbox found!\n";
- $dbh->disconnect();
+ rhimport::closedb($dbh);
exit 1;
}
@@ -113,7 +111,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";
- $dbh->disconnect();
+ rhimport::closedb($dbh);
exit 0;
}
@@ -153,13 +151,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";
- $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;
}
@@ -205,7 +203,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;