aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2017-08-24 19:48:52 +0530
committerArun Isaac2017-08-24 19:49:54 +0530
commita373039e0608f58150f15cb5f0c35c8771ffcaa0 (patch)
treeedeb591d15740d271af0f8f04b693c0497502f82
parent6e8484bd344b814be1dc472e2cebc5fb70cea27e (diff)
downloadnasa-apod-gnu-social-bot-a373039e0608f58150f15cb5f0c35c8771ffcaa0.tar.gz
nasa-apod-gnu-social-bot-a373039e0608f58150f15cb5f0c35c8771ffcaa0.tar.lz
nasa-apod-gnu-social-bot-a373039e0608f58150f15cb5f0c35c8771ffcaa0.zip
Add comments.
* apod-bot.sh: Add comments.
-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)"'