check all authors on start rate limit X

main
Shane 7 months ago
parent 5561516481
commit 1d4fe844c3
  1. 11
      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:

Loading…
Cancel
Save