|
|
|
|
@ -8,6 +8,10 @@ from foodie_utils import ( |
|
|
|
|
import time |
|
|
|
|
import sys |
|
|
|
|
import os |
|
|
|
|
import smtplib |
|
|
|
|
from email.mime.text import MIMEText |
|
|
|
|
from email.mime.multipart import MIMEMultipart |
|
|
|
|
from foodie_config import EMAIL_CONFIG |
|
|
|
|
|
|
|
|
|
# Configure logging |
|
|
|
|
logging.basicConfig( |
|
|
|
|
@ -16,6 +20,39 @@ logging.basicConfig( |
|
|
|
|
) |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
def send_capacity_alert(username, remaining, reset_time): |
|
|
|
|
"""Send email alert when an author's tweet capacity is full.""" |
|
|
|
|
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} |
|
|
|
|
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
|
def display_author_status(author): |
|
|
|
|
"""Display detailed status for a single author.""" |
|
|
|
|
username = author['username'] |
|
|
|
|
@ -38,6 +75,10 @@ def display_author_status(author): |
|
|
|
|
print(f" • Reset time: {reset_time}") |
|
|
|
|
print(f" • Can post: {'Yes' if can_post else 'No'}") |
|
|
|
|
|
|
|
|
|
# Send alert if capacity is full |
|
|
|
|
if remaining == 0: |
|
|
|
|
send_capacity_alert(username, remaining, reset_time) |
|
|
|
|
|
|
|
|
|
# Show API status for verification |
|
|
|
|
if not is_any_script_running(): |
|
|
|
|
api_remaining, api_reset = get_x_rate_limit_status(author) |
|
|
|
|
|