update real time rate limiting checks for X

This commit is contained in:
2025-05-08 16:27:10 +10:00
parent 01bab56eb6
commit 447bfb0087
7 changed files with 284 additions and 195 deletions
+15 -6
View File
@@ -319,10 +319,14 @@ def post_weekly_thread():
continue
# Check if the author can post before generating the thread
can_post, remaining, reset = check_author_rate_limit(author)
if not can_post:
reset_time = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(reset)) if reset else "Unknown"
logging.info(f"Skipping weekly thread for {username} due to rate limit. Remaining: {remaining}, Reset at: {reset_time}")
if check_author_rate_limit(author):
reset_time = datetime.fromtimestamp(
load_json_file('/home/shane/foodie_automator/rate_limit_info.json', default={})
.get(username, {})
.get('tweet_reset', time.time()),
tz=timezone.utc
).strftime('%Y-%m-%d %H:%M:%S')
logging.info(f"Skipping weekly thread for {username} due to rate limit. Reset at: {reset_time}")
continue
# Select top 2 posts (to fit within 3-tweet limit: lead + 2 posts)
@@ -359,12 +363,17 @@ def post_weekly_thread():
# Post final CTA tweet
final_cta = generate_final_cta(author)
if final_cta:
post_tweet(author, final_cta, reply_to_id=lead_tweet_id)
logging.info(f"Posted final CTA tweet for {username}: {final_cta}")
cta_response = post_tweet(author, final_cta, reply_to_id=lead_tweet_id)
if cta_response:
logging.info(f"Posted final CTA tweet for {username}: {final_cta}")
else:
logging.warning(f"Failed to post final CTA tweet for {username}")
except Exception as e:
logging.error(f"Error posting thread for {username}: {e}", exc_info=True)
continue
logging.info("Completed foodie_weekly_thread.py")
def main():
"""Main function to run the script."""
lock_fd = None