diff --git a/post.sh b/post.sh index 4f2ef98..f7bc409 100755 --- a/post.sh +++ b/post.sh @@ -46,13 +46,23 @@ if [ -z ${FNAME} ]; then FNAME="./config/quotes" fi -! test -s "${FNAME}" && find "./src" -type f -iname "*.txt" | shuf >"${FNAME}" +function shift_list() { + ! test -s "${FNAME}" && find "./src" -type f -iname "*.txt" | shuf >"${FNAME}" -QUOTE_FNAME=$(head -1 "${FNAME}") -tail -n +2 "${FNAME}" > "${FNAME}.tmp" && mv "${FNAME}.tmp" "${FNAME}" + QUOTE_FNAME=$(head -1 "${FNAME}") + tail -n +2 "${FNAME}" > "${FNAME}.tmp" && mv "${FNAME}.tmp" "${FNAME}" +} -if [ ${TWEETMODE} ]; then +function post_tweet() { ./util/tweet.py -c "${CREDENTIALS}" send -f "${QUOTE_FNAME}" + return $? +} + +shift_list + +if [ ${TWEETMODE} ]; then + # Keep going until a tweet was posted + while post_tweet; [ $? -ne 0 ]; do shift_list; done else cat ${QUOTE_FNAME} fi diff --git a/util/tweet.py b/util/tweet.py index 2e72eb7..0f54f20 100755 --- a/util/tweet.py +++ b/util/tweet.py @@ -72,11 +72,14 @@ else: print("[ERROR]: Could not read from file.") logger.error(f"[{get_time_fmt()}] Could not read from file: {tweet_filename}; " + os.strerror(e.errno)) + sys.exit(1) else: if len(tweet_text) <= 280: api.update_status(tweet_text) + sys.exit(0) else: print("[ERROR]: Tweet text too long!") logger.error(f"[{get_time_fmt()}] Tweet contents too long; argument length: " + f"{len(tweet_text)}; file location: {args.tweet_filename}") + sys.exit(1)