From 14f8d7a6af77263c8a4a81971b0b31422c2faceb Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 2 Sep 2017 23:39:48 +0530 Subject: Downcase variable names. * apod-bot.sh: Downcase variable names. --- apod-bot.sh | 44 ++++++++++++++++++++++---------------------- 1 file 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)"' -- cgit v1.2.3