1
0
Fork 0
MastodonMegafono/megafono_bot.sh
2019-02-20 02:25:43 +01:00

43 lines
No EOL
772 B
Bash
Executable file

#
# CONFIGURATION
#
# Interval between two consecutive posts
SLEEP_INTERVAL=3h
# File containing the toots to post
DATA_FILE=megafono.txt
#
# CONFIGURATION END
#
extract_image() {
sed -n -e 's/.*<img>\(.*\)<\/img>.*/\1/p' <<< $1
}
extract_text() {
sed -e "s/<img>.*<\/img>/ /g" <<< $1
}
while :
do
# Last line should be empty, so we dont need an additional read here
# after the while loop
while read line
do
text="#avviso%0A"`extract_text "$line"`
image=`extract_image "$line"`
echo "[$(date)][INFO] Now tooting: $text"
if [ "$image" != "" ]
then
echo "[$(date)][INFO] with image: $image"
./toot.sh -i=images/$image $text >/dev/null 2>&1 &
else
./toot.sh $text >/dev/null 2>&1 &
fi
sleep ${SLEEP_INTERVAL}
done < ${DATA_FILE}
done