From 9ad176d854450b7474a4857dae76974249514dea Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 3 Sep 2017 00:34:13 +0530 Subject: Improve duplicate notice detection. * apod-bot.sh: Use jq comparison to detect duplicate notice. --- apod-bot.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apod-bot.sh b/apod-bot.sh index 67e3a04..81fc5c3 100755 --- a/apod-bot.sh +++ b/apod-bot.sh @@ -40,13 +40,9 @@ page_link=$apod_base_url/ap$date.html notice="$title $page_link $media_link" # Ensure we are not publishing a duplicate notice -previous_notice=$(curl -sSu "$bot_username:$bot_password" $social_api_url/statuses/home_timeline.json \ - | jq -r '.[0] | .text') -if [[ "$notice" = "$previous_notice" ]] -then - echo "Notice \"$notice\" already published. Aborting..." >&2 - exit 1 -fi +curl -sSu "$bot_username:$bot_password" $social_api_url/statuses/home_timeline.json \ + | jq -e --arg notice "$notice" '(.[0] | .text) != $notice' > /dev/null \ + || (echo "Notice \"$notice\" already published. Aborting..." >&2 && exit 1) # Check image and page links exist wget --spider $media_link -- cgit v1.2.3