update to post all authors

main
Shane 7 months ago
parent 3fc99a8a28
commit e2e5adbff5
  1. 79
      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'
state = load_json_file(state_file, default={'last_author_index': -1})
delay_seconds = 30 # Delay between posts to avoid rate limits and spread engagement
print("Getting next author") # Iterate through all authors
author = get_next_author_round_robin() for index, author in enumerate(AUTHORS):
if not author: username = author['username']
print("No authors available due to rate limits") print(f"Processing author: {username}")
logging.info("No authors available due to rate limits") logging.info(f"Processing author: {username}")
sleep_time = 86400 # 1 day for cron
return False, sleep_time
print(f"Selected author: {author['username']}")
try: try:
print("Checking rate limit") print("Checking rate limit")
if not check_author_rate_limit(author): # Pass the full author dictionary if not check_author_rate_limit(author):
print(f"Rate limit exceeded for {author['username']}") print(f"Rate limit exceeded for {username}, skipping")
logging.info(f"Rate limit exceeded for {author['username']}") logging.info(f"Rate limit exceeded for {username}, skipping")
sleep_time = 86400 # 1 day continue
return False, sleep_time
print("Generating tweet") print("Generating tweet")
tweet = generate_engagement_tweet(author) tweet = generate_engagement_tweet(author)
if not tweet: if not tweet:
print(f"Failed to generate tweet for {author['username']}") print(f"Failed to generate tweet for {username}, skipping")
logging.error(f"Failed to generate engagement tweet for {author['username']}, skipping") logging.error(f"Failed to generate engagement tweet for {username}, skipping")
sleep_time = 86400 # 1 day continue
return False, sleep_time
print(f"Posting tweet: {tweet}") print(f"Posting tweet: {tweet}")
logging.info(f"Posting engagement tweet for {author['username']}: {tweet}") logging.info(f"Posting engagement tweet for {username}: {tweet}")
if post_tweet(author, tweet): if post_tweet(author, tweet):
print(f"Successfully posted tweet for {author['username']}") print(f"Successfully posted tweet for {username}")
logging.info(f"Successfully posted engagement tweet for {author['username']}") logging.info(f"Successfully posted engagement tweet for {username}")
posted = True posted = True
else: # Update last_author_index to maintain round-robin consistency
print(f"Failed to post tweet for {author['username']}") state['last_author_index'] = index
logging.warning(f"Failed to post engagement tweet for {author['username']}") save_json_file(state_file, state)
except Exception as e: else:
print(f"Error posting tweet for {author['username']}: {e}") print(f"Failed to post tweet for {username}")
logging.error(f"Error posting engagement tweet for {author['username']}: {e}", exc_info=True) 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)
except Exception as e:
print(f"Error posting tweet for {username}: {e}")
logging.error(f"Error posting tweet for {username}: {e}", exc_info=True)
continue
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