From 243ca1d0593c165064a92e387fdee5da041b7748 Mon Sep 17 00:00:00 2001 From: Sleeping Crows Date: Mon, 27 Nov 2023 12:19:57 -0500 Subject: [PATCH] fa.sh - First pass on latest Submission ID Fetch. --- Furaffinity/fa.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Furaffinity/fa.sh b/Furaffinity/fa.sh index 03644b6..3da3fa8 100755 --- a/Furaffinity/fa.sh +++ b/Furaffinity/fa.sh @@ -1,8 +1,7 @@ #!/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 +maxsubs=52089873 #sets the default maximum bound of submission depth, should be left here if the max bound can't be updated for whatever reason. # It's recommended to set the max subs yourself, as there isn't a good # way to poll the website and check for that. @@ -64,6 +63,21 @@ fi done +# Note: curl Doesn't seem to care if the cookies file is missing, probably don't need to add case statements. yay? +# Pull the main page of FA to get the latest Submission ID. + +echo "debug: Pulling furaffinity.net index page for latest Sub ID." +mainpagefetch=$(curl -b "./cookies.txt" -s --stderr - https://www.furaffinity.net/) +# find the first figure id field and cut it down before changing maxsubs. +maxsubidparse=$(grep -m1 -Po 'figure id="\K[^"]*' <<< "$mainpagefetch" | cut -c 5-) +echo "debug: $maxsubidparse" +if [[ -n "$maxsubidparse" ]]; then + echo "debug: Latest Known Sub ID Was $maxsubidparse" + maxsubs=$maxsubidparse +else + echo "debug: couldn't get latest known Sub ID, falling back to hardcoded Sub ID." +fi + echo "debug: amount of submissions requested: $rep" if [[ -z "$minsubarg" ]]; then echo "debug: no minimum sub id given" @@ -100,7 +114,6 @@ do # curl the url if it's not in the list already # see if it errors out for not existing in the database. result=$(curl -b "./cookies.txt" -s --stderr - https://www.furaffinity.net/view/$ranid) - header= title=$(grep -m 1 "title" <<< "$result" | cut -c 12- | rev | cut -c 35- | rev) if grep -q "not in our database" <<< "$result"; then echo "($i of $rep) $ranid does not exist, logged and re-rolling."