update realtime rate limit for X
This commit is contained in:
@@ -8,7 +8,7 @@ import fcntl
|
||||
import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from openai import OpenAI
|
||||
from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, load_post_counts, save_post_counts
|
||||
from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, check_author_rate_limit
|
||||
from foodie_config import X_API_CREDENTIALS, AUTHOR_BACKGROUNDS_FILE
|
||||
from dotenv import load_dotenv
|
||||
|
||||
@@ -161,23 +161,15 @@ def post_engagement_tweet():
|
||||
logging.info("Starting foodie_engagement_tweet.py")
|
||||
print("Starting foodie_engagement_tweet.py")
|
||||
|
||||
# Load post counts to check limits
|
||||
post_counts = load_post_counts()
|
||||
|
||||
for author in AUTHORS:
|
||||
# Check if the author can post before generating the tweet
|
||||
can_post, remaining, reset = check_author_rate_limit(author)
|
||||
if not can_post:
|
||||
reset_time = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(reset)) if reset else "Unknown"
|
||||
logging.info(f"Skipping engagement tweet for {author['username']} due to rate limit. Remaining: {remaining}, Reset at: {reset_time}")
|
||||
continue
|
||||
|
||||
try:
|
||||
# Check post limits
|
||||
author_count = next((entry for entry in post_counts if entry["username"] == author["username"]), None)
|
||||
if not author_count:
|
||||
logging.error(f"No post count entry for {author['username']}, skipping")
|
||||
continue
|
||||
if author_count["monthly_count"] >= 500:
|
||||
logging.warning(f"Monthly post limit (500) reached for {author['username']}, skipping")
|
||||
continue
|
||||
if author_count["daily_count"] >= 15:
|
||||
logging.warning(f"Daily post limit (15) reached for {author['username']}, skipping")
|
||||
continue
|
||||
|
||||
tweet = generate_engagement_tweet(author)
|
||||
if not tweet:
|
||||
logging.error(f"Failed to generate engagement tweet for {author['username']}, skipping")
|
||||
@@ -187,10 +179,6 @@ def post_engagement_tweet():
|
||||
print(f"Posting engagement tweet for {author['username']}: {tweet}")
|
||||
if post_tweet(author, tweet):
|
||||
logging.info(f"Successfully posted engagement tweet for {author['username']}")
|
||||
# Update post counts
|
||||
author_count["monthly_count"] += 1
|
||||
author_count["daily_count"] += 1
|
||||
save_post_counts(post_counts)
|
||||
else:
|
||||
logging.warning(f"Failed to post engagement tweet for {author['username']}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user