From 1d4fe844c38329e53414a7dc998a812815c220b2 Mon Sep 17 00:00:00 2001 From: Shane Date: Fri, 9 May 2025 11:54:50 +1000 Subject: [PATCH] check all authors on start rate limit X --- foodie_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/foodie_utils.py b/foodie_utils.py index 550051e..7ec2024 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -1215,6 +1215,10 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400): remaining = max_tweets reset = current_time + tweet_window_seconds logger.warning(f"Test tweet failed for {username}, resetting quota to {max_tweets}") + # Ensure reset is in the future + if reset <= current_time: + logger.warning(f"Reset time {reset} is in the past for {username}. Setting to 24 hours from now.") + reset = current_time + tweet_window_seconds # Update author info with synced quota author_info = { 'tweet_remaining': remaining, @@ -1225,11 +1229,8 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400): rate_limit_info[username] = author_info save_json_file(rate_limit_file, rate_limit_info) - # Calculate remaining tweets based on tweets posted in this run - remaining = author_info['tweet_remaining'] - author_info['tweets_posted_in_run'] - reset = author_info['tweet_reset'] - # Check if quota has reset + reset = author_info['tweet_reset'] if current_time >= reset: logger.info(f"Quota reset for {username}, restoring to {max_tweets} tweets") remaining = max_tweets @@ -1239,6 +1240,8 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400): author_info['tweets_posted_in_run'] = 0 rate_limit_info[username] = author_info save_json_file(rate_limit_file, rate_limit_info) + else: + remaining = author_info['tweet_remaining'] - author_info['tweets_posted_in_run'] can_post = remaining > 0 if not can_post: