Source code for my personal quote bot project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implemented logic to retry tweeting if operation failed.

Audrey f1733d13 750bbfcf

+17 -4
+14 -4
post.sh
··· 46 46 FNAME="./config/quotes" 47 47 fi 48 48 49 - ! test -s "${FNAME}" && find "./src" -type f -iname "*.txt" | shuf >"${FNAME}" 49 + function shift_list() { 50 + ! test -s "${FNAME}" && find "./src" -type f -iname "*.txt" | shuf >"${FNAME}" 50 51 51 - QUOTE_FNAME=$(head -1 "${FNAME}") 52 - tail -n +2 "${FNAME}" > "${FNAME}.tmp" && mv "${FNAME}.tmp" "${FNAME}" 52 + QUOTE_FNAME=$(head -1 "${FNAME}") 53 + tail -n +2 "${FNAME}" > "${FNAME}.tmp" && mv "${FNAME}.tmp" "${FNAME}" 54 + } 53 55 54 - if [ ${TWEETMODE} ]; then 56 + function post_tweet() { 55 57 ./util/tweet.py -c "${CREDENTIALS}" send -f "${QUOTE_FNAME}" 58 + return $? 59 + } 60 + 61 + shift_list 62 + 63 + if [ ${TWEETMODE} ]; then 64 + # Keep going until a tweet was posted 65 + while post_tweet; [ $? -ne 0 ]; do shift_list; done 56 66 else 57 67 cat ${QUOTE_FNAME} 58 68 fi
+3
util/tweet.py
··· 72 72 print("[ERROR]: Could not read from file.") 73 73 logger.error(f"[{get_time_fmt()}] Could not read from file: {tweet_filename}; " + 74 74 os.strerror(e.errno)) 75 + sys.exit(1) 75 76 else: 76 77 if len(tweet_text) <= 280: 77 78 api.update_status(tweet_text) 79 + sys.exit(0) 78 80 else: 79 81 print("[ERROR]: Tweet text too long!") 80 82 logger.error(f"[{get_time_fmt()}] Tweet contents too long; argument length: " + 81 83 f"{len(tweet_text)}; file location: {args.tweet_filename}") 84 + sys.exit(1) 82 85