From d117725ae875385deb6c29c3d09b197677db8394 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Tue, 2 Dec 2014 21:29:06 -0600 Subject: [PATCH] More gracefully handle deleted posts --- fetch | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/fetch b/fetch index 74d49d6..6ce856a 100755 --- a/fetch +++ b/fetch @@ -8,17 +8,25 @@ Usage: $(basename "${0}") Given an ID number from the site: * downloads and stashes the full-size image in the md5 directory * adds whatever tags are found into the tag area + + -p Associates the downloaded image with a pool + -i Used with -p to indicate the position in the pool + + -t Refresh the tags, not the picture + -f If the image is deleted, provide the local filename EOF kill $$ exit 1 } -while getopts p:i: OPT +while getopts p:i:tf: OPT do case "${OPT}" in p) pool="${OPTARG}" ;; i) indx="${OPTARG}" ;; - ?) pebkac ;; + t) tags=TAGS ;; + f) hash="${OPTARG}" ;; + ?) pebkac ;; esac done shift $(( $OPTIND - 1 )) @@ -50,16 +58,31 @@ cd "$(dirname "${0}")" file="$(image_url "${id}")" tags="$(image_tags "${id}")" -[ "${file}" -a "${tags}" ] || { echo "Nothing found!"; kill $$; exit 1; } +[ "${file}" -o "${hash}" ] || { echo "No download URL (deleted?) and -f not provided" >&2; kill -ABRT $$; exit 1; } +[ "${tags}" ] || { echo "No tags found" >&2; kill -ABRT $$; exit 1; } -name="$(basename "${file}")" +if [ "${file}" ] +then + name="$(basename "${file}")" +else + name="${hash}" +fi extn="${name#*.}" -if [ -e "md5/${name}" ] +unset nabbed +if [ "${file}" ] +then + if [ -e "md5/${name}" ] + then + echo "Filename md5/${name} already exists" + else + wget -O "md5/${name}" "${file}" + nabbed=NABBED + fi +fi + +if [ "${nabbed}" -o "${tags}" ] then - echo "Filename md5/${name} already exists" -else - wget -O "md5/${name}" "${file}" for tag in ${tags} do echo ${tag} -- 2.42.0