bio-dynamie/scrapers/org.bio-dynamie.sh

152 lines
5.5 KiB
Bash
Raw Permalink Normal View History

2021-05-30 21:40:59 +02:00
#!/bin/bash
2021-06-08 16:16:09 +02:00
## eFile is older than "nn min ago"
if [[ $(date +%s -r /tmp/index.html) -lt $(date +%s --date="1440 min ago") ]]; then
cd /tmp; rm -f index.html; rm -f /tmp/buffer
wget https://www.bio-dynamie.org/jardinage/demarrer/
2021-06-08 16:16:09 +02:00
fi
2021-07-10 02:23:23 +02:00
[[ ! -f /tmp/index.html ]] && exit 1
## C'est quoi demain
DAY=$(date +%A | awk '{ print toupper( substr( $0, 1, 1 ) ) substr( $0, 2 ); }')
DAYE=$(date +%A --date="1 day" | awk '{ print toupper( substr( $0, 1, 1 ) ) substr( $0, 2 ); }')
2021-08-01 19:51:14 +02:00
DOM=$(date +%d)
TOM=$(date +%d --date="1 day")
DEND=$(date +%d/%m --date="2 day")
T0=$(echo $DOM | sed 's/^0*//')
T1=$(echo $TOM | sed 's/^0*//')
MONTH=$(date +%m)
MONTHE=$(date +%m --date="1 day")
2021-05-30 21:40:59 +02:00
YEAR=$(date +%Y)
YEARE=$(date +%Y --date="1 day")
## TRANSLATION
2021-05-30 21:40:59 +02:00
[[ $DAY == "Monday" ]] && DAY="Lundi" && DAYE="Mardi"
[[ $DAY == "Tuesday" ]] && DAY="Mardi" && DAYE="Mercredi"
[[ $DAY == "Wednesday" ]] && DAY="Mercredi" && DAYE="Jeudi"
[[ $DAY == "Thursday" ]] && DAY="Jeudi" && DAYE="Vendredi"
[[ $DAY == "Friday" ]] && DAY="Vendredi" && DAYE="Samedi"
[[ $DAY == "Saturday" ]] && DAY="Samedi" && DAYE="Dimanche"
[[ $DAY == "Sunday" ]] && DAY="Dimanche" && DAYE="Mardi"
## EXTRACT SEMAINES
count=$(cat /tmp/index.html | awk '/Semaine/{s=x}{s=s$0"\n"}/Semaine/{print s}' | grep -v ^$ | wc -l | cut -d ' ' -f 1)
x=1
while [ $x -le $count ]
do
SEM="$(cat /tmp/index.html | awk '/Semaine/{s=x}{s=s$0"\n"}/Semaine/{print s}' | grep -v ^$ | head -n $x | tail -n 1)"
echo "$x : $SEM"
A=$(echo "$SEM" | awk -F 'du ' '{print $2}' | cut -d ' ' -f 1 | sed 's|[^0-9]||g')
A0=$(echo "$A" | sed 's/^0*//')
B=$(echo "$SEM" | awk -F 'au ' '{print $2}' | cut -d ' ' -f 1 | sed 's|[^0-9]||g')
B0=$(echo "$B" | sed 's/^0*//')
echo "($x) : SEMAINE: T0=$T0 T1=$T1 A0=$A0 B0=$B0"
# CHECK WEEK INTERVAL
2021-08-01 13:40:07 +02:00
if [[ $T0 -le $T1 ]]; then
echo "($x) : SEMAINE: $A <= $T1 <= $B"
[[ $T1 -ge $A0 && $T1 -le $B0 ]] && echo "OK: ($x) $A - $B" && S=$x && break
else
echo "($x) : SEMAINE: $B <= $T1 <= $A"
[[ $T1 -le $A0 && $T1 -ge $B0 ]] && echo "REVERSE: ($x) $A - $B" && S=$x && break
fi
x=$(( $x + 1 ))
done
2021-05-30 21:40:59 +02:00
echo "##################################################################"
echo "Demain nous serons $DAYE $TOM/$MONTHE/$YEARE (SEMAINE $S)"
2021-05-30 21:40:59 +02:00
echo "##################################################################"
2021-08-01 19:51:14 +02:00
[[ "$S" == "" ]] && echo "IMPOSSIBLE DE TROUVER LA BONNE SEMAINE" && exit 1
2021-05-30 21:40:59 +02:00
# BROKEN cat /tmp/index.html | awk "/$DOM\/$MONTH\/$YEAR/{s=x}{s=s$0\"\n\"}/$TOM\/$MONTH\/$YEAR/{print s}" | html2text -utf8
2021-08-01 19:51:14 +02:00
function splitweek()
{
str="$(tr '\n' ' ' < /tmp/buffer)"
delimiter="$1"
s=$str$delimiter
array=();
while [[ $s ]]; do
array+=( "${s%%"$delimiter"*}" );
s=${s#*"$delimiter"};
done;
# declare -p array
2021-08-01 20:38:39 +02:00
echo "$1${array[$2]}" | awk -F "$DEND" '{print $1}' | sed s/\/\'/g | sed s/\…/./g | sed s/\/./g
2021-08-01 19:51:14 +02:00
}
2021-05-30 21:40:59 +02:00
#read
if [[ "$DAYE" == "Lundi" ]]; then
echo "LUNDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
LUNDI=$(cat /tmp/index.html | awk '/Lundi/{s=x}{s=s$0"\n"}/Mardi/{print s}' | html2text -utf8 | awk '/Lundi/{s=x}{s=s$0"\n"}/Mardi/{print s}')
echo "$LUNDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
#read
if [[ "$DAYE" == "Mardi" ]]; then
echo "MARDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
MARDI=$(cat /tmp/index.html | awk '/Mardi/{s=x}{s=s$0"\n"}/Mercredi/{print s}' | html2text -utf8 | awk '/Mardi/{s=x}{s=s$0"\n"}/Mercredi/{print s}')
echo "$MARDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
#read
if [[ "$DAYE" == "Mercredi" ]]; then
echo "MERCREDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
MERCREDI=$(cat /tmp/index.html | awk '/Mercredi/{s=x}{s=s$0"\n"}/Jeudi/{print s}' | html2text -utf8 | awk '/Mercredi/{s=x}{s=s$0"\n"}/Jeudi/{print s}')
echo "$MERCREDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
#read
if [[ "$DAYE" == "Jeudi" ]]; then
echo "JEUDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
JEUDI=$(cat /tmp/index.html | awk '/Jeudi/{s=x}{s=s$0"\n"}/Vendredi/{print s}' | html2text -utf8 | awk '/Jeudi/{s=x}{s=s$0"\n"}/Vendredi/{print s}')
echo "$JEUDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
#read
if [[ "$DAYE" == "Vendredi" ]]; then
echo "VENDREDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
VENDREDI=$(cat /tmp/index.html | awk '/ Vendredi/{s=x}{s=s$0"\n"}/ Samedi/{print s}' | html2text -utf8 | awk '/ Vendredi/{s=x}{s=s$0"\n"}/ Samedi/{print s}')
echo "$VENDREDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
fi
2021-05-30 21:40:59 +02:00
#read
if [[ "$DAYE" == "Samedi" ]]; then
echo "SAMEDI $TOM/$MONTHE $S"
2021-08-01 19:51:14 +02:00
SAMEDI=$(cat /tmp/index.html | awk '/Samedi/{s=x}{s=s$0"\n"}/Dimanche/{print s}' | html2text -utf8 | awk '/Samedi/{s=x}{s=s$0"\n"}/Dimanche/{print s}')
echo "$SAMEDI" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
#read
if [[ "$DAYE" == "Dimanche" ]]; then
echo "DIMANCHE $TOM/$MONTHE $S"
DIMANCHE=$(cat /tmp/index.html | awk '/Dimanche/{s=x}{s=s$0"\n"}/#Lune/{print s}' | html2text -utf8 | awk '/Dimanche/{s=x}{s=s$0"\n"}/#Lune/{print s}' | awk -F "#Lune" '{print $1}')
echo "$DIMANCHE" > /tmp/buffer
2021-08-01 19:51:14 +02:00
splitweek "$DAYE" "$S" > /tmp/sms_BIODYN
fi
if [[ "$DAYE" == "Lundi" ]]; then
echo "__________LUNE__________"
LUNE=$(cat /tmp/index.html | awk '/#Lune/{s=x}{s=s$0"\n"}/\.#/{print s}' | html2text -utf8 | awk -F 'Lundi' '{print $1}')
2021-08-01 19:51:14 +02:00
echo "$LUNE" > /tmp/buffer
splitweek "#Lune" "$S" >> /tmp/sms_BIODYN
2021-05-30 21:40:59 +02:00
fi
echo "##################################################################"
echo "SMS"
2021-05-30 21:44:57 +02:00
echo "##################################################################"
2021-07-12 20:53:10 +02:00
cat /tmp/sms_BIODYN
2021-05-30 21:44:57 +02:00
echo "##################################################################"
2021-07-10 02:23:23 +02:00
exit 0