4
0
Fork 1
forked from encrypt/toot
MastodonMegafono/megafono_bot.sh

46 lines
969 B
Bash
Raw Normal View History

2019-02-20 12:28:23 +01:00
#!/bin/bash
2019-02-19 16:45:15 +01:00
#
# CONFIGURATION
#
2019-02-19 13:53:09 +01:00
2019-02-19 16:45:15 +01:00
# Interval between two consecutive posts
FLOOR_HOUR_SLEEP_INTERVAL=5
CEILING_HOUR_SLEEP_INTERVAL=19
2019-02-19 13:53:09 +01:00
2019-02-19 16:45:15 +01:00
# File containing the toots to post
2019-12-08 17:03:46 +01:00
if [ ! -z "$1" ]; then
DATA_FILE=$1
else
2019-02-21 10:52:30 +01:00
DATA_FILE=megafono.txt
2019-12-08 17:03:46 +01:00
fi
2019-02-19 16:45:15 +01:00
# CONFIGURATION END
#
random_time_on_range(){
FLOOR=$1
CEILING=$2
RANGE=$(($CEILING-$FLOOR+1));
#echo "You will generate a random number between $FLOOR and $CEILING (both inclusive). There are $RANGE possible numbers!"
RESULT=$RANDOM;
#echo "We just generated the random number $RESULT, which might not be in the range we want";
let "RESULT %= $RANGE";
RESULT=$(($RESULT+$FLOOR));
echo $RESULT;
}
2019-02-19 13:57:34 +01:00
while :
2019-02-19 13:53:09 +01:00
do
2019-02-19 13:57:34 +01:00
# Last line should be empty, so we dont need an additional read here
# after the while loop
while read line
do
eval ./toot.sh $line
SLEEP_TOOT=$(random_time_on_range $FLOOR_HOUR_SLEEP_INTERVAL $CEILING_HOUR_SLEEP_INTERVAL)
sleep $SLEEP_TOOT"h"
2019-02-19 16:45:15 +01:00
done < ${DATA_FILE}
2019-02-19 13:57:34 +01:00
done