aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapod-bot.sh13
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)"'