|
|
|
|
@ -3,7 +3,8 @@ 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, is_any_script_running |
|
|
|
|
get_x_rate_limit_status, update_system_activity, is_any_script_running, |
|
|
|
|
save_json_file |
|
|
|
|
) |
|
|
|
|
import time |
|
|
|
|
import sys |
|
|
|
|
@ -20,8 +21,41 @@ logging.basicConfig( |
|
|
|
|
) |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
# File to track sent notifications |
|
|
|
|
NOTIFICATION_FILE = '/home/shane/foodie_automator/notification_tracking.json' |
|
|
|
|
|
|
|
|
|
def load_notification_tracking(): |
|
|
|
|
"""Load notification tracking data.""" |
|
|
|
|
return load_json_file(NOTIFICATION_FILE, default={}) |
|
|
|
|
|
|
|
|
|
def save_notification_tracking(tracking_data): |
|
|
|
|
"""Save notification tracking data.""" |
|
|
|
|
save_json_file(NOTIFICATION_FILE, tracking_data) |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
tracking[username] = { |
|
|
|
|
'last_notification': datetime.now(timezone.utc).isoformat(), |
|
|
|
|
'reset_time': reset_time |
|
|
|
|
} |
|
|
|
|
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): |
|
|
|
|
logger.info(f"Skipping duplicate notification for {username}") |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
msg = MIMEMultipart() |
|
|
|
|
msg['From'] = EMAIL_CONFIG['from_email'] |
|
|
|
|
|