diff options
author | Arun Isaac | 2017-09-03 02:28:56 +0530 |
---|---|---|
committer | Arun Isaac | 2017-09-03 02:28:56 +0530 |
commit | e0687eea08c860373f3b0202960825d0f57f8cfa (patch) | |
tree | 527c3a834da2bce6cd4a150d25594f716f9968ae | |
parent | 9f4ebeade27115510a8d863a303b1cafa8ddb9fa (diff) | |
download | nasa-apod-gnu-social-bot-e0687eea08c860373f3b0202960825d0f57f8cfa.tar.gz nasa-apod-gnu-social-bot-e0687eea08c860373f3b0202960825d0f57f8cfa.tar.lz nasa-apod-gnu-social-bot-e0687eea08c860373f3b0202960825d0f57f8cfa.zip |
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.
-rwxr-xr-x | apod-bot.sh | 13 |
1 files 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)"' |