Bash-Scripts/Furaffinity/fa.sh

100 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
i=1
rep=$1 # how many submissions to generate
#To Do: use Curl to scrape furaffinity.net's main page and find a way to parse down to the first submission found.
maxsubs=52089873 #sets the default maximum bound of submission depth
# It's recommended to set the max subs yourself, as there isn't a good
# way to poll the website and check for that.
minsubs=0 #sets the default minimum bound of submission depth
minsubarg=$2
echo "===FA.SH: The Random FA Sub Generator==="
validate=1
# Validate the rep count is only numbers.
while [ $validate -eq 1 ]
do
if [[ -z "$rep" ]]; then
validate=1
echo "///"
echo "How many submissions to pull? (Default: 1)"
echo "///"
read rep
fi
if [[ -n "$rep" ]]; then
echo "Debug: Checking Submission Input."
if [[ $rep != [0-9]* ]]; then
echo "Submission Argument Not an Integer."
unset rep
else
((validate--));
fi
fi
done
echo "debug: amount of submissions requested: $rep"
if [[ -z "$minsubarg" ]]; then
echo "debug: no minimum sub id given"
else
echo "debug: minimum sub id: $minsubarg"
fi
echo "debug: max sub id: $maxsubs"
if [[ $minsubarg -gt $minsubs ]]; then
minsubs=$minsubarg
else
minsubs=$minsubs
fi
echo "debug: min sub id: $minsubs"
repeat=1
while [ $repeat -eq 1 ]
do
while [ $i -le $rep ]
do
ranid=$(shuf -i $minsubs-$maxsubs -n1)
if grep -w $ranid already-checked.txt; then #check if it's been seen before, re-roll without iterating the loop and check again.
echo "😿 Already presented $ranid , re-rolling."
else
# curl the url if it's not in the list already
# see if it errors out for not existing in the database.
result=$(curl -s --stderr - https://www.furaffinity.net/view/$ranid)
if grep -q "not in our database" <<< "$result"; then
echo "($i of $rep) $ranid does not exist, logged and re-rolling."
echo "$ranid" >> already-checked.txt
sleep 0.5
elif grep -q "pending deletion" <<< "$result"; then
echo "($i of $rep) $ranid is pending deletion, logged and re-rolling."
echo "$ranid" >> already-checked.txt
sleep 0.5
# if it passes the second test, run the main script.
else
# Only upticks the counter on a hit.
xdg-open https://furaffinity.net/view/$ranid 2> /dev/null
echo "$ranid" >> already-checked.txt
echo "($i of $rep) 🔫 New Submission! $ranid "
counts=$(wc already-checked.txt | awk '{print $1}')
sleep 0.5 #to avoid site throttling.
((i++))
fi
fi
done
echo "viewed $counts pages so far."
read -r -p "😼 Do you want to go another $rep? (Y/n): " answer
case $answer in
[Yy]* ) echo "Going for another round!"; i=0;;
[Nn]* ) ((repeat--)); echo "Ok, bye!";;
* ) echo "Going for another round!"; i=0;;
esac
done
exit