diff options
Diffstat (limited to 'rhimport-zffe')
-rwxr-xr-x | rhimport-zffe | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/rhimport-zffe b/rhimport-zffe new file mode 100755 index 0000000..b5ebad1 --- /dev/null +++ b/rhimport-zffe @@ -0,0 +1,105 @@ +#!/usr/bin/perl -w +# +# +# rhimport +# +# Copyright (C) 2009 Christian Pointner <equinox@helsinki.at> +# +# This file is part of rhimport. +# +# rhimport is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# rhimport is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with rhimport. If not, see <http://www.gnu.org/licenses/>. +# + +use strict; +use Switch; +use Date::Calc; +use Time::localtime; +use IO::Handle; +use IPC::Open3; + +use lib '/usr/local/share/rhimport/'; +use rhimport; + +my $STAT_FILE = $ENV{'HOME'} . "/rhimport-zffe.stat"; +my $ZF_NOTE_FILE = $ENV{'HOME'} . "/rhimport-zf.last_note"; +my $ZF_NEW_FILE = $ENV{'HOME'} . "/rhimport-zf.is_new"; +my $FE_NOTE_FILE = $ENV{'HOME'} . "/rhimport-fe.last_note"; +my $FE_NEW_FILE = $ENV{'HOME'} . "/rhimport-fe.is_new"; +my $PV_ID = '359'; + +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + +if($#ARGV >= 0 && $ARGV[0] eq 'last') { + print "!!!This is the last attempt, there won't be a retry on error!!!\n" +} + +my @import_day = Date::Calc::Today(); +my $import_date = sprintf("%04d-%02d-%02d", @import_day); +my $current_date = `cat $STAT_FILE`; +if($current_date eq $import_date) { + print "Already created note of today\n"; + $dbh->disconnect(); + exit 0; +} + +unless(-e $ZF_NEW_FILE) { + print "zip-fm not yet imported - "; + if($#ARGV >= 0 && $ARGV[0] eq 'last') { + print "giving up, rebroadcasting last show"; + } else { + print "will retry later\n"; + exit 0, + } +} + +unless(-e $FE_NEW_FILE) { + print "focus europa not yet imported - "; + if($#ARGV >= 0 && $ARGV[0] eq 'last') { + print "giving up, rebroadcasting last show"; + } else { + print "will retry later\n"; + exit 0, + } +} + +sub get_note { + my ($file) = @_; + my @lines = read_file($file, binmode => ':utf8', err_mode => 'quiet'); + return "" unless ($lines[0]); + + chomp($lines[0]); + $lines[0] = "<p><strong>$lines[0]</strong></p>\n"; + return join('',@lines); +}; + +my $sum_title = "focus europa, zip-fm (WH)"; +my $sum_text = get_note($FE_NOTE_FILE) . "<br/>\n"; +$sum_text = $sum_text . get_note($ZF_NOTE_FILE) . "<br/>\n"; +$sum_text = $sum_text . "<br/><br/>\n"; + +print "\nsummary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; +rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_day), "1"); +print "\n"; + +unlink($STAT_FILE); +open(my $fhs, '>', $STAT_FILE); +print $fhs $import_date; +close($fhs); + +unlink($ZF_NEW_FILE); +unlink($FE_NEW_FILE); + +exit 0; |