update to post all authors

main
Shane 7 months ago
parent 3fc99a8a28
commit e2e5adbff5
  1. 85
      foodie_engagement_tweet.py

@ -214,49 +214,58 @@ def generate_engagement_tweet(author):
return None return None
def post_engagement_tweet(): def post_engagement_tweet():
"""Post engagement tweets for authors daily.""" """Post engagement tweets for all authors with a delay between posts."""
print("Entering post_engagement_tweet") print("Entering post_engagement_tweet")
try: try:
logging.info("Starting foodie_engagement_tweet.py") logging.info("Starting foodie_engagement_tweet.py")
posted = False posted = False
state_file = '/home/shane/foodie_automator/author_state.json'
print("Getting next author") state = load_json_file(state_file, default={'last_author_index': -1})
author = get_next_author_round_robin() delay_seconds = 30 # Delay between posts to avoid rate limits and spread engagement
if not author:
print("No authors available due to rate limits") # Iterate through all authors
logging.info("No authors available due to rate limits") for index, author in enumerate(AUTHORS):
sleep_time = 86400 # 1 day for cron username = author['username']
return False, sleep_time print(f"Processing author: {username}")
print(f"Selected author: {author['username']}") logging.info(f"Processing author: {username}")
try:
print("Checking rate limit")
if not check_author_rate_limit(author):
print(f"Rate limit exceeded for {username}, skipping")
logging.info(f"Rate limit exceeded for {username}, skipping")
continue
print("Generating tweet")
tweet = generate_engagement_tweet(author)
if not tweet:
print(f"Failed to generate tweet for {username}, skipping")
logging.error(f"Failed to generate engagement tweet for {username}, skipping")
continue
print(f"Posting tweet: {tweet}")
logging.info(f"Posting engagement tweet for {username}: {tweet}")
if post_tweet(author, tweet):
print(f"Successfully posted tweet for {username}")
logging.info(f"Successfully posted engagement tweet for {username}")
posted = True
# Update last_author_index to maintain round-robin consistency
state['last_author_index'] = index
save_json_file(state_file, state)
else:
print(f"Failed to post tweet for {username}")
logging.warning(f"Failed to post tweet for {username}")
# Add delay between posts (except for the last author)
if index < len(AUTHORS) - 1:
print(f"Waiting {delay_seconds} seconds before next post")
logging.info(f"Waiting {delay_seconds} seconds before next post")
time.sleep(delay_seconds)
try: except Exception as e:
print("Checking rate limit") print(f"Error posting tweet for {username}: {e}")
if not check_author_rate_limit(author): # Pass the full author dictionary logging.error(f"Error posting tweet for {username}: {e}", exc_info=True)
print(f"Rate limit exceeded for {author['username']}") continue
logging.info(f"Rate limit exceeded for {author['username']}")
sleep_time = 86400 # 1 day
return False, sleep_time
print("Generating tweet")
tweet = generate_engagement_tweet(author)
if not tweet:
print(f"Failed to generate tweet for {author['username']}")
logging.error(f"Failed to generate engagement tweet for {author['username']}, skipping")
sleep_time = 86400 # 1 day
return False, sleep_time
print(f"Posting tweet: {tweet}")
logging.info(f"Posting engagement tweet for {author['username']}: {tweet}")
if post_tweet(author, tweet):
print(f"Successfully posted tweet for {author['username']}")
logging.info(f"Successfully posted engagement tweet for {author['username']}")
posted = True
else:
print(f"Failed to post tweet for {author['username']}")
logging.warning(f"Failed to post engagement tweet for {author['username']}")
except Exception as e:
print(f"Error posting tweet for {author['username']}: {e}")
logging.error(f"Error posting engagement tweet for {author['username']}: {e}", exc_info=True)
print("Completed post_engagement_tweet") print("Completed post_engagement_tweet")
logging.info("Completed foodie_engagement_tweet.py") logging.info("Completed foodie_engagement_tweet.py")

Loading…
Cancel
Save