aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapod-bot.sh6
1 files changed, 6 insertions, 0 deletions
diff --git a/apod-bot.sh b/apod-bot.sh
index d0a5386..b79f261 100755
--- a/apod-bot.sh
+++ b/apod-bot.sh
@@ -12,12 +12,14 @@
# To run this script, you will need jq, the command line JSON
# processor and pup, the command line HTML processor.
+# Settings
SOCIAL_API_URL=https://social.systemreboot.net/api
BOT_USERNAME=apod
BOT_PASSWORD=secret-password-here
APOD_BASE_URL=https://apod.nasa.gov/apod
+# Download HTML page, and scrape required information
APOD_HTML=$(curl $APOD_BASE_URL/astropix.html)
TITLE=$(echo "$APOD_HTML" | pup 'center:nth-child(2) > b:nth-child(1) text{}' \
@@ -34,8 +36,10 @@ fi
DATE=$(echo "$APOD_HTML" | pup ':contains("Discuss") attr{href}' | awk -F= '{print $2}')
PAGE_LINK=$APOD_BASE_URL/ap$DATE.html
+# Construct notice
NOTICE="$TITLE $PAGE_LINK $MEDIA_LINK"
+# Ensure we are not publishing a duplicate notice
PREVIOUS_NOTICE=$(curl -u "$BOT_USERNAME:$BOT_PASSWORD" $SOCIAL_API_URL/statuses/home_timeline.json \
| jq -r '.[0] | .text')
if [[ "$NOTICE" = "$PREVIOUS_NOTICE" ]]
@@ -44,9 +48,11 @@ then
exit 1
fi
+# Check image and page links exist
wget --spider $MEDIA_LINK
wget --spider $PAGE_LINK
+# Publish notice
curl -u "$BOT_USERNAME:$BOT_PASSWORD" --data-urlencode "status=$NOTICE" \
$SOCIAL_API_URL/statuses/update.json \
| jq -r '"Published notice \"\(.text)\" on \(.created_at)"'