diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-26 20:40:24 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-26 20:40:24 (GMT) |
commit | 81531b51fe70fee446d22d3505d04709cd7b5b8a (patch) | |
tree | 782e0ebbc4ae0ec451219e8072aa0dbbe701b4e7 /rhautoimport-zffe | |
parent | eb3f9d2ca6675997311307308437c8bddde59a64 (diff) |
renamed rhimport to rhautoimport
Diffstat (limited to 'rhautoimport-zffe')
-rwxr-xr-x | rhautoimport-zffe | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/rhautoimport-zffe b/rhautoimport-zffe new file mode 100755 index 0000000..eb4c1a1 --- /dev/null +++ b/rhautoimport-zffe @@ -0,0 +1,118 @@ +#!/usr/bin/perl -w +# +# +# rhautoimport +# +# Copyright (C) 2009-2015 Christian Pointner <equinox@helsinki.at> +# +# This file is part of rhautoimport. +# +# rhautoimport 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. +# +# rhautoimport 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 rhautoimport. 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 File::Slurp; + +use lib '/usr/local/share/rhautoimport/'; +use rhautoimport; + +my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-zffe.stat"; +my $ZF_NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-zf.last_note"; +my $ZF_NEW_FILE = $ENV{'HOME'} . "/rhautoimport-zf.is_new"; +my $FE_NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-fe.last_note"; +my $FE_NEW_FILE = $ENV{'HOME'} . "/rhautoimport-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 @today = Date::Calc::Today(); +my $dow = Date::Calc::Day_of_Week(@today); +my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1); + +my @tmp = Date::Calc::Standard_to_Business(@today); +$tmp[2] = 1; +my @this_mon = Date::Calc::Business_to_Standard(@tmp); +my @next_mon = Date::Calc::Add_Delta_Days($this_mon[0], $this_mon[1], $this_mon[2], 7); + +my @import_day = @tomorrow; +if ($dow == 5) { + @import_day = @next_mon; +} + +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"; + 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 . "<br/>\n" . get_note($ZF_NOTE_FILE) . "<br/>\n"; +$sum_text = $sum_text . "<br/><br/>\n"; + +print "\nsummary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; +rhautoimport::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; |