update to post all authors
This commit is contained in:
+47
-38
@@ -214,49 +214,58 @@ def generate_engagement_tweet(author):
|
||||
return None
|
||||
|
||||
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")
|
||||
try:
|
||||
logging.info("Starting foodie_engagement_tweet.py")
|
||||
posted = False
|
||||
|
||||
print("Getting next author")
|
||||
author = get_next_author_round_robin()
|
||||
if not author:
|
||||
print("No authors available due to rate limits")
|
||||
logging.info("No authors available due to rate limits")
|
||||
sleep_time = 86400 # 1 day for cron
|
||||
return False, sleep_time
|
||||
print(f"Selected author: {author['username']}")
|
||||
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
|
||||
|
||||
try:
|
||||
print("Checking rate limit")
|
||||
if not check_author_rate_limit(author): # Pass the full author dictionary
|
||||
print(f"Rate limit exceeded for {author['username']}")
|
||||
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)
|
||||
# Iterate through all authors
|
||||
for index, author in enumerate(AUTHORS):
|
||||
username = author['username']
|
||||
print(f"Processing 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)
|
||||
|
||||
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")
|
||||
logging.info("Completed foodie_engagement_tweet.py")
|
||||
|
||||
Reference in New Issue
Block a user