diff --git a/check_x_capacity.py b/check_x_capacity.py index f7b11bf..276a7f4 100755 --- a/check_x_capacity.py +++ b/check_x_capacity.py @@ -22,16 +22,23 @@ def display_author_status(author): can_post, remaining, reset = check_author_rate_limit(author) reset_time = datetime.fromtimestamp(reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') + # Get detailed API status first + api_remaining, api_reset = get_x_rate_limit_status(author) + if api_remaining is not None: + api_reset_time = datetime.fromtimestamp(api_reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') + # Use API values as primary display + remaining = api_remaining + reset_time = api_reset_time + can_post = remaining > 0 + status = "✅" if can_post else "❌" print(f"\n{status} {username}:") print(f" • Remaining tweets: {remaining}/17") print(f" • Reset time: {reset_time}") print(f" • Can post: {'Yes' if can_post else 'No'}") - # Get detailed API status - api_remaining, api_reset = get_x_rate_limit_status(author) + # Show API status for verification if api_remaining is not None: - api_reset_time = datetime.fromtimestamp(api_reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') print(f" • API Status: {api_remaining} remaining, resets at {api_reset_time}") def display_total_capacity(): @@ -46,6 +53,12 @@ def display_total_capacity(): for author in AUTHORS: can_post, remaining, _ = check_author_rate_limit(author) + # Get API status for accurate count + api_remaining, _ = get_x_rate_limit_status(author) + if api_remaining is not None: + remaining = api_remaining + can_post = remaining > 0 + used = 17 - remaining total_used += used if can_post: diff --git a/foodie_utils.py b/foodie_utils.py index eb98983..b66e4d9 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -1667,6 +1667,7 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400): logger.info(f"At least one script is running, using stored rate limit info for {username}") remaining = author_info.get('tweet_remaining', max_tweets) reset = author_info.get('tweet_reset', current_time + tweet_window_seconds) + # Check if reset time has passed if current_time >= reset: logger.info(f"Reset time passed for {username}, resetting quota") @@ -1677,6 +1678,7 @@ 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) + # Adjust for tweets posted in this run remaining = remaining - author_info.get('tweets_posted_in_run', 0) else: