From e0687eea08c860373f3b0202960825d0f57f8cfa Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 3 Sep 2017 02:28:56 +0530 Subject: Organize GNU Social API calls with new `send-request' function. * apod-bot.sh (send-request): New function. Invoke `send-request' for all GNU Social API calls. --- apod-bot.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apod-bot.sh b/apod-bot.sh index ffa2a1d..5527077 100755 --- a/apod-bot.sh +++ b/apod-bot.sh @@ -19,8 +19,13 @@ bot_password=secret-password-here apod_base_url=https://apod.nasa.gov/apod +function send-request { + # Send request to GNU Social server + curl -sSfu "$bot_username:$bot_password" "$@" +} + # Check if the bot username/password are correct -curl -sSfu "$bot_username:$bot_password" -o /dev/null $social_api_url/statuses/home_timeline.json +send-request -o /dev/null $social_api_url/statuses/home_timeline.json # Download HTML page, and scrape required information apod_html=$(curl -sS $apod_base_url/astropix.html) @@ -41,7 +46,7 @@ page_link=$apod_base_url/ap$date.html notice="$title $page_link $media_link" # Ensure we are not publishing a duplicate notice -curl -sSu "$bot_username:$bot_password" $social_api_url/statuses/home_timeline.json \ +send-request $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) @@ -50,6 +55,6 @@ 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 \ +send-request --data-urlencode "status=$notice" \ + $social_api_url/statuses/update.json \ | jq -r '"Published notice \"\(.text)\" on \(.created_at)"' -- cgit v1.2.3