aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2017-09-02 23:39:48 +0530
committerArun Isaac2017-09-02 23:39:48 +0530
commit14f8d7a6af77263c8a4a81971b0b31422c2faceb (patch)
treea3e69b1f1ea3bf8f4b86da7406680a5ae0abca04
parent6f92bf82e50fd608f4ec0eaa95f9936b9b202412 (diff)
downloadnasa-apod-gnu-social-bot-14f8d7a6af77263c8a4a81971b0b31422c2faceb.tar.gz
nasa-apod-gnu-social-bot-14f8d7a6af77263c8a4a81971b0b31422c2faceb.tar.lz
nasa-apod-gnu-social-bot-14f8d7a6af77263c8a4a81971b0b31422c2faceb.zip
Downcase variable names.
* apod-bot.sh: Downcase variable names.
-rwxr-xr-xapod-bot.sh44
1 files changed, 22 insertions, 22 deletions
diff --git a/apod-bot.sh b/apod-bot.sh
index 4e7085a..67e3a04 100755
--- a/apod-bot.sh
+++ b/apod-bot.sh
@@ -13,46 +13,46 @@
# 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
+social_api_url=https://social.systemreboot.net/api
+bot_username=apod
+bot_password=secret-password-here
-APOD_BASE_URL=https://apod.nasa.gov/apod
+apod_base_url=https://apod.nasa.gov/apod
# Download HTML page, and scrape required information
-APOD_HTML=$(curl -sS $APOD_BASE_URL/astropix.html)
+apod_html=$(curl -sS $apod_base_url/astropix.html)
-TITLE=$(echo "$APOD_HTML" | pup 'center:nth-child(2) > b:nth-child(1) text{}' \
+title=$(echo "$apod_html" | pup 'center:nth-child(2) > b:nth-child(1) text{}' \
| sed -e 's/^ *//' -e 's/ *$//')
-IMAGE_LINK=$APOD_BASE_URL/$(echo "$APOD_HTML" | pup -p 'img attr{src}')
-YOUTUBE_VIDEO_ID=$(echo "$APOD_HTML" | pup 'iframe attr{src}' | awk -F/ '{print $5}' | awk -F? '{print $1}')
-YOUTUBE_LINK="https://www.youtube.com/watch?v=$YOUTUBE_VIDEO_ID"
-if [[ -z "$YOUTUBE_VIDEO_ID" ]]
+image_link=$apod_base_url/$(echo "$apod_html" | pup -p 'img attr{src}')
+youtube_video_id=$(echo "$apod_html" | pup 'iframe attr{src}' | awk -F/ '{print $5}' | awk -F? '{print $1}')
+youtube_link="https://www.youtube.com/watch?v=$youtube_video_id"
+if [[ -z "$youtube_video_id" ]]
then
- MEDIA_LINK=$IMAGE_LINK
+ media_link=$image_link
else
- MEDIA_LINK=$YOUTUBE_LINK
+ media_link=$youtube_link
fi
-DATE=$(echo "$APOD_HTML" | pup ':contains("Discuss") attr{href}' | awk -F= '{print $2}')
-PAGE_LINK=$APOD_BASE_URL/ap$DATE.html
+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"
+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 \
+previous_notice=$(curl -sSu "$bot_username:$bot_password" $social_api_url/statuses/home_timeline.json \
| jq -r '.[0] | .text')
-if [[ "$NOTICE" = "$PREVIOUS_NOTICE" ]]
+if [[ "$notice" = "$previous_notice" ]]
then
- echo "Notice \"$NOTICE\" already published. Aborting..." >&2
+ echo "Notice \"$notice\" already published. Aborting..." >&2
exit 1
fi
# Check image and page links exist
-wget --spider $MEDIA_LINK
-wget --spider $PAGE_LINK
+wget --spider $media_link
+wget --spider $page_link
# Publish notice
-curl -sSu "$BOT_USERNAME:$BOT_PASSWORD" --data-urlencode "status=$NOTICE" \
- $SOCIAL_API_URL/statuses/update.json \
+curl -sSu "$bot_username:$bot_password" --data-urlencode "status=$notice" \
+ $social_api_url/statuses/update.json \
| jq -r '"Published notice \"\(.text)\" on \(.created_at)"'