blockbot/hash.sh

68 lines
1.3 KiB
Bash

#!/bin/bash
#############################
STATS_MESSAGE="Top Hash Tags on the Fediverse right now:"
BOT_ACCOUNT="hashbot@poster.place"
############################
getTags() {
DATA=$(curl https://fedi.buzz/ | grep -i tags | cut -d '/' -f5 | sed 's/">//' | sort -u | sed 's/^/#/')
MESSAGE="$STATS_MESSAGE $DATA"
toot activate $BOT_ACCOUNT
echo $DATA | toot post
}
background_daemon() {
echo
echo "HashTag running in Daemon Mode"
echo
echo
while true; do
echo "Current Time: `date`"
if [[ `date | cut -d " " -f4` == *"06:00:"* ]]; then
echo "Checking for new blocks.......";echo
getTags
fi
if [[ `date | cut -d " " -f4` == *"12:00:"* ]]; then
echo "Checking for new blocks.......";echo
getTags
fi
if [[ `date | cut -d " " -f4` == *"18:00:"* ]]; then
echo "Checking for new blocks.......";echo
getTags
fi
echo "#######################################"
echo "Sleeping for 30 seconds........."
echo "#######################################"
sleep 30
done
}
background(){
if [[ `date` == *":00"* ]]; then
background_daemon
else
echo "Waiting for time to be in sync...."
sleep 1
background
fi
}
help() {
echo
echo "hash.sh daemon"
echo
echo "hash.sh print"
echo "hash.sh help"
echo
echo
}
if [ "$1" = "daemon" ]; then
background
elif [ "$1" = "blocks" ]; then
print "$2"
else
help
fi