|
|
|
|
@ -1182,7 +1182,7 @@ def check_author_rate_limit(author, max_tweets=17, tweet_window_seconds=86400): |
|
|
|
|
# Load rate limit info |
|
|
|
|
rate_limit_info = load_json_file(rate_limit_file, default={}) |
|
|
|
|
|
|
|
|
|
# Get script run ID (set at startup in foodie_automator_rss.py) |
|
|
|
|
# Get script run ID |
|
|
|
|
if not hasattr(check_author_rate_limit, "script_run_id"): |
|
|
|
|
check_author_rate_limit.script_run_id = int(current_time) |
|
|
|
|
logger.info(f"Set script_run_id to {check_author_rate_limit.script_run_id}") |
|
|
|
|
@ -1308,8 +1308,29 @@ def get_x_rate_limit_status(author): |
|
|
|
|
headers = response.headers |
|
|
|
|
|
|
|
|
|
# Extract app-level rate limit info from headers |
|
|
|
|
remaining = int(headers.get('x-rate-limit-remaining', 0)) |
|
|
|
|
reset = int(headers.get('x-rate-limit-reset', 0)) |
|
|
|
|
remaining_str = headers.get('x-rate-limit-remaining') |
|
|
|
|
reset_str = headers.get('x-rate-limit-reset') |
|
|
|
|
if remaining_str is None or reset_str is None: |
|
|
|
|
logger.error(f"Rate limit headers missing for {username}: {headers}") |
|
|
|
|
return None, None |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
remaining = int(remaining_str) |
|
|
|
|
reset = int(reset_str) |
|
|
|
|
except ValueError as e: |
|
|
|
|
logger.error(f"Failed to parse rate limit headers for {username}: remaining={remaining_str}, reset={reset_str}, error={e}") |
|
|
|
|
return None, None |
|
|
|
|
|
|
|
|
|
# Validate remaining tweets |
|
|
|
|
if remaining < 0 or remaining > 17: # Free tier max is 17 |
|
|
|
|
logger.warning(f"Invalid remaining tweets for {username}: {remaining}. Capping at 17.") |
|
|
|
|
remaining = min(remaining, 17) |
|
|
|
|
|
|
|
|
|
# Ensure reset is in the future |
|
|
|
|
current_time = int(time.time()) |
|
|
|
|
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 + 86400 # 24 hours |
|
|
|
|
|
|
|
|
|
if response.status_code == 201: |
|
|
|
|
# Delete the test tweet |
|
|
|
|
|