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-fw | |
parent | e6035cca7cf6f23b3965f6238e41103838c48d3b (diff) |
refactoring
Diffstat (limited to 'rhimport-fw')
-rwxr-xr-x | rhimport-fw | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/rhimport-fw b/rhimport-fw index 3a3f6e5..45b0b2c 100755 --- a/rhimport-fw +++ b/rhimport-fw @@ -22,7 +22,6 @@ # use strict; -use DBI; use Date::Calc; use XML::Feed; use XML::Feed::Entry; @@ -36,11 +35,6 @@ use HTML::Entities; 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-fw.stat"; my $LAST_FILE = $ENV{'HOME'} . "/rhimport-fw.last"; my $RSS_URL = "http://cba.fro.at/seriesrss/263965?c=Kfs2IoV2Wmd"; @@ -59,14 +53,18 @@ my $user = `/usr/bin/id -un`; $user =~ s/\n//; my $group = "freiewelle"; -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 $idx = 0; my $idx_reb = 1; if(scalar(@allowed_dbs) != 2) { print "found more or less than 2 Dropboxes for this group?!\n"; - $dbh->disconnect(); + rhimport::closedb($dbh); exit 1; } my $dropbox = $allowed_dbs[$idx]->{'PATH'}; @@ -95,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"; - $dbh->disconnect(); + rhimport::closedb($dbh); exit 0; } @@ -134,13 +132,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"; - $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; } @@ -193,7 +191,7 @@ $log .= $import_log; ($ret, $import_log) = rhimport::import_single($file, $dropbox_reb, $user, 0, $error_cb); $log .= $import_log; -$dbh->disconnect(); +rhimport::closedb($dbh); unlink $file; |