Created
September 4, 2015 22:17
-
-
Save TheBlackParrot/c328579ec929c5e44be6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
IMG_DIR="/srv/http/getaphrase-tweeter/image-queue/" | |
LOG_FILE="/tmp/getaphrase_log.log" | |
CHOSEN_IMG=$(find "$IMG_DIR" -type f | shuf -n 1) | |
if [[ -z "$CHOSEN_IMG" ]]; then | |
echo "[$(date)] No images to tweet" >> "$LOG_FILE" | |
else | |
IMAGE_FN=$(basename "$CHOSEN_IMG") | |
MEDIA_ID=$(twurl -H upload.twitter.com -X POST "/1.1/media/upload.json" --file "$CHOSEN_IMG" --file-field "media" | jq -r '.media_id_string') | |
if ! [[ -z "$MEDIA_ID" ]]; then | |
RESULT=$(twurl "/1.1/statuses/update.json" -d "media_ids=$MEDIA_ID" | jq -r '.created_at') | |
if [[ $RESULT == "null" ]]; then | |
echo "[$(date)] (!!) Failed to tweet $IMAGE_FN, was not posted" >> "$LOG_FILE" | |
else | |
rm -R -f $CHOSEN_IMG | |
echo "[$(date)] Tweeted $IMAGE_FN" >> "$LOG_FILE" | |
fi | |
else | |
echo "[$(date)] (!!) Failed to tweet $IMAGE_FN, no media ID given" >> "$LOG_FILE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment