4
0
Fork 1
forked from encrypt/toot
MastodonMegafono/megafono_bot.sh
2019-02-19 15:56:54 +00:00

43 lines
No EOL
775 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>\(.*\)/\1\2/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=`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