-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcron_switchingreport.sh
executable file
·98 lines (79 loc) · 2.93 KB
/
cron_switchingreport.sh
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
#!/bin/bash
# Generates the report of the previous month unless you provide an isodate
# in that case generate sthe report of the month containing the date.
die() {
[ -z "$1" ] || echo -e '\033[34;1mError: '$*'\033[0m' >&2
emili.py \
--subject "ERROR: Informe cambios de comercializador, $year-$month" \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--from [email protected] \
--config $scriptpath/dbconfig.py \
--format md \
--style somenergia.css \
--body "$*" \
exit -1
}
step() {
echo -e '\033[34;1m:: '$*'\033[0m'
}
execucio=$(date)
step "Execució a $execucio"
scriptpath=$(dirname $(readlink -f "$0"))
cd "$scriptpath"
today=$(date -I)
# Data fixa per enviar informes antics
#today='2021-10-15'
IFS='-' read -r year month day <<< "$today" # split date
lastMonthEnd=$(date -I -d "$year-$month-01 - 1 day") # last day of last month
# Data fixa per enviar informes antics
#lastMonthEnd='2021-09-30'
IFS='-' read -r year month day <<< "${1:-$lastMonthEnd}" # split date
step "Generant resum del $year-$month-$day"
# Incrementar la seqüència quan s'envia per segon cop...
sequence=01
out=$(python cron_informe_cnmc_canvi_comer.py $year $month $sequence 2>&1)
allreports=(/tmp/SI_R2-???_E_${year}${month}_${sequence}.xml)
csvreports=(/tmp/SI_R2-???_E_${year}${month}_${sequence}.csv)
step "allreports: $allreports"
lastReport=${allreports[*]: -1}
step "lastReport: $lastReport"
MONTHS=("" Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre)
monthname=${MONTHS[$((10#$month))]}
step "Enviant resultats..."
TEXTOK="
# Informe de Cambios de comercializadora para SomEnergia $monthname de $year
Les adjuntamos el informe de cambios de comercializador correspondiente al
mes de ${MONTHS[$((10#$month))]} de $year para la comercializadora \"Som Energia SCCL\".
Un saludo.
"
emili.py \
--subject "SomEnergia SCCL, informe cambios de comercializador, $year-$month" \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--from [email protected] \
--replyto [email protected] \
--config $scriptpath/dbconfig.py \
--format md \
--style somenergia.css \
$lastReport \
$csvreports \
--body "$TEXTOK" \
|| die "Error enviant fitxers CSV als companys: $out"
emili.py \
--subject "SomEnergia SCCL, informe cambios de comercializador, $year-$month" \
--to [email protected] \
--to [email protected] \
--bcc [email protected] \
--from [email protected] \
--replyto [email protected] \
--config $scriptpath/dbconfig.py \
--format md \
--style somenergia.css \
$lastReport \
--body "$TEXTOK" \
|| die "Error enviant missatge a la CNMC: $out"