diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-07-22 13:34:05 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-07-22 13:34:05 (GMT) |
commit | 6fb972eec6953a40d57b76b7894952abdc4437d2 (patch) | |
tree | 8d0f567c0d366327ffd5a7939646ea398be549d2 /rhimport-dn | |
parent | e6035cca7cf6f23b3965f6238e41103838c48d3b (diff) |
refactoring
Diffstat (limited to 'rhimport-dn')
-rwxr-xr-x | rhimport-dn | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/rhimport-dn b/rhimport-dn index 47933f4..4f6275a 100755 --- a/rhimport-dn +++ b/rhimport-dn @@ -22,7 +22,6 @@ # use strict; -use DBI; use Date::Calc; use Time::localtime; use XML::Feed; @@ -36,11 +35,6 @@ use IPC::Open3; 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-dn.stat"; my $FILES_RSS_URL = "http://www.democracynow.org/podcast-stations.xml"; my $HEADLINES_RSS_URL = "http://www.democracynow.org/podcast.xml"; @@ -64,7 +58,11 @@ my $user = `/usr/bin/id -un`; $user =~ s/\n//; my $group = "democracyn"; -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); @@ -96,7 +94,7 @@ for my $href ( @allowed_dbs ) { if($dropbox eq "") { print "no dropbox for day in question\n"; - $dbh->disconnect(); + rhimport::closedb($dbh); exit 0; } @@ -122,13 +120,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"; - $dbh->disconnect(); + rhimport::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"; - $dbh->disconnect(); + rhimport::closedb($dbh); exit 1; } @@ -219,7 +217,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; |