update real time rate limiting checks for X

This commit is contained in:
2025-05-08 16:27:10 +10:00
parent 01bab56eb6
commit 447bfb0087
7 changed files with 284 additions and 195 deletions
+8 -8
View File
@@ -159,14 +159,17 @@ def post_engagement_tweet():
"""Post engagement tweets for authors daily."""
try:
logging.info("Starting foodie_engagement_tweet.py")
print("Starting foodie_engagement_tweet.py")
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}")
if check_author_rate_limit(author):
reset_time = datetime.fromtimestamp(
load_json_file('/home/shane/foodie_automator/rate_limit_info.json', default={})
.get(author['username'], {})
.get('tweet_reset', time.time()),
tz=timezone.utc
).strftime('%Y-%m-%d %H:%M:%S')
logging.info(f"Skipping engagement tweet for {author['username']} due to rate limit. Reset at: {reset_time}")
continue
try:
@@ -176,7 +179,6 @@ def post_engagement_tweet():
continue
logging.info(f"Posting engagement tweet for {author['username']}: {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']}")
else:
@@ -186,10 +188,8 @@ def post_engagement_tweet():
continue
logging.info("Completed foodie_engagement_tweet.py")
print("Completed foodie_engagement_tweet.py")
except Exception as e:
logging.error(f"Unexpected error in post_engagement_tweet: {e}", exc_info=True)
print(f"Error in post_engagement_tweet: {e}")
def main():
"""Main function to run the script."""