From 33287c8a4ecadf13cb98b90bcbff61f4ad5c55a4 Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 14 May 2025 16:49:27 +1000 Subject: [PATCH] add new X post check --- check_x_capacity.py | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 check_x_capacity.py diff --git a/check_x_capacity.py b/check_x_capacity.py new file mode 100755 index 0000000..f7b11bf --- /dev/null +++ b/check_x_capacity.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +import logging +from datetime import datetime, timezone +from foodie_utils import ( + AUTHORS, check_author_rate_limit, load_json_file, + get_x_rate_limit_status, update_system_activity +) +import time +import sys +import os + +# Configure logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s' +) +logger = logging.getLogger(__name__) + +def display_author_status(author): + """Display detailed status for a single author.""" + username = author['username'] + can_post, remaining, reset = check_author_rate_limit(author) + reset_time = datetime.fromtimestamp(reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') + + status = "✅" if can_post else "❌" + print(f"\n{status} {username}:") + print(f" • Remaining tweets: {remaining}/17") + print(f" • Reset time: {reset_time}") + print(f" • Can post: {'Yes' if can_post else 'No'}") + + # Get detailed API status + api_remaining, api_reset = get_x_rate_limit_status(author) + if api_remaining is not None: + api_reset_time = datetime.fromtimestamp(api_reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') + print(f" • API Status: {api_remaining} remaining, resets at {api_reset_time}") + +def display_total_capacity(): + """Display total capacity across all authors.""" + total_capacity = len(AUTHORS) * 17 + total_used = 0 + available_authors = 0 + + print("\n=== X Posting Capacity Status ===") + print(f"Total daily capacity: {total_capacity} tweets ({len(AUTHORS)} authors × 17 tweets)") + print("\nAuthor Status:") + + for author in AUTHORS: + can_post, remaining, _ = check_author_rate_limit(author) + used = 17 - remaining + total_used += used + if can_post: + available_authors += 1 + display_author_status(author) + + print("\n=== Summary ===") + print(f"Total tweets used today: {total_used}") + print(f"Total tweets remaining: {total_capacity - total_used}") + print(f"Authors available to post: {available_authors}/{len(AUTHORS)}") + + # Calculate percentage used + percent_used = (total_used / total_capacity) * 100 + print(f"Capacity used: {percent_used:.1f}%") + + if percent_used > 80: + print("\n⚠️ Warning: High capacity usage! Consider adding more authors.") + elif percent_used > 60: + print("\nℹ️ Note: Moderate capacity usage. Monitor usage patterns.") + +def main(): + try: + # Update system activity + update_system_activity("check_x_capacity", "running", os.getpid()) + + # Display capacity status + display_total_capacity() + + # Update system activity + update_system_activity("check_x_capacity", "stopped") + + except KeyboardInterrupt: + print("\nScript interrupted by user") + update_system_activity("check_x_capacity", "stopped") + sys.exit(0) + except Exception as e: + logger.error(f"Error: {e}") + update_system_activity("check_x_capacity", "stopped") + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file