diff --git a/check_x_capacity.py b/check_x_capacity.py index 10f1028..bea4257 100755 --- a/check_x_capacity.py +++ b/check_x_capacity.py @@ -44,53 +44,46 @@ def should_send_notification(username, reset_time): """Check if we should send a notification for this author.""" tracking = load_notification_tracking() author_data = tracking.get(username, {}) - - # If we've never notified for this author or the reset time has changed - if not author_data or author_data.get('reset_time') != reset_time: - # Update tracking + reset_time_str = str(reset_time) + if not author_data or str(author_data.get('reset_time')) != reset_time_str: tracking[username] = { 'last_notification': datetime.now(timezone.utc).isoformat(), - 'reset_time': reset_time + 'reset_time': reset_time_str } save_notification_tracking(tracking) return True - return False def send_capacity_alert(username, remaining, reset_time): """Send email alert when an author's tweet capacity is full.""" - # Check if we should send notification - if not should_send_notification(username, reset_time): + # Always use string for reset_time + reset_time_str = str(reset_time) + if not should_send_notification(username, reset_time_str): logger.info(f"Skipping duplicate notification for {username}") return - try: msg = MIMEMultipart() msg['From'] = EMAIL_CONFIG['from_email'] msg['To'] = EMAIL_CONFIG['to_email'] msg['Subject'] = f"⚠️ X Capacity Alert: {username}" - body = f""" X Tweet Capacity Alert! Username: {username} Time: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')} Remaining Tweets: {remaining}/17 - Reset Time: {reset_time} + Reset Time: {reset_time_str} This author has reached their daily tweet limit. The quota will reset at the time shown above. This is an automated alert from your foodie_automator system. """ - msg.attach(MIMEText(body, 'plain')) - with smtplib.SMTP(EMAIL_CONFIG['smtp_server'], EMAIL_CONFIG['smtp_port']) as server: server.starttls() server.login(EMAIL_CONFIG['smtp_username'], EMAIL_CONFIG['smtp_password']) server.send_message(msg) - logger.info(f"Sent capacity alert email for {username}") except Exception as e: logger.error(f"Failed to send capacity alert email: {e}")