1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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;
|