try
This commit is contained in:
+12
-7
@@ -1778,21 +1778,26 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400):
|
||||
logger.debug(f"[DEBUG] NO scripts running, will call get_x_rate_limit_status for {username}")
|
||||
remaining, api_reset = get_x_rate_limit_status(author)
|
||||
logger.debug(f"[DEBUG] API returned: remaining={remaining}, api_reset={api_reset} for {username}")
|
||||
|
||||
if remaining is None or api_reset is None:
|
||||
# Fallback: Use last known quota or assume 0 remaining
|
||||
if current_time < author_info.get('tweet_reset', current_time + tweet_window_seconds):
|
||||
# If API call fails, use the stored rate limit info
|
||||
remaining = author_info.get('tweet_remaining', 0)
|
||||
reset = author_info.get('tweet_reset', current_time + tweet_window_seconds)
|
||||
logger.warning(f"Test tweet failed for {username}, using last known quota: {remaining} remaining")
|
||||
else:
|
||||
remaining = 0 # Assume exhausted if API fails and reset time has passed
|
||||
|
||||
# If reset time has passed, assume quota is exhausted
|
||||
if current_time >= reset:
|
||||
remaining = 0
|
||||
reset = current_time + tweet_window_seconds
|
||||
logger.warning(f"Test tweet failed for {username}, assuming quota exhausted")
|
||||
logger.warning(f"Reset time passed and API check failed for {username}, assuming quota exhausted")
|
||||
else:
|
||||
logger.warning(f"API check failed for {username}, using stored quota: {remaining} remaining")
|
||||
else:
|
||||
# API call succeeded, update with actual values
|
||||
remaining = min(remaining, max_tweets) # Ensure within Free tier limit
|
||||
reset = api_reset
|
||||
logger.info(f"Updated rate limit info from API for {username}: {remaining} remaining")
|
||||
|
||||
# Update author info but preserve tweets_posted_in_run
|
||||
# Update author info
|
||||
author_info['tweet_remaining'] = remaining
|
||||
author_info['tweet_reset'] = reset
|
||||
# Don't reset tweets_posted_in_run here
|
||||
|
||||
Reference in New Issue
Block a user