#!/usr/bin/env python3 """ Script to reset alert notification status for testing This clears the last_notified_at timestamp so alerts will trigger again """ import asyncio import sys from pathlib import Path # Add parent directory to path sys.path.insert(0, str(Path(__file__).parent.parent)) from app.database import connect_db, disconnect_db, get_db import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) async def reset_alert_notifications(): """Reset all alerts' last_notified_at to allow re-triggering""" try: # Connect to database await connect_db() db = await get_db() # Reset all active alerts result = await db.search_alerts.update_many( {"is_active": True}, {"$set": {"last_notified_at": None}} ) logger.info(f"✅ Reset {result.modified_count} alert(s)") # Show active alerts alerts = await db.search_alerts.find({"is_active": True}).to_list(length=None) if alerts: logger.info(f"\n{'='*60}") logger.info(f"Active Alerts (Ready to Trigger Again):") logger.info(f"{'='*60}") for alert in alerts: logger.info(f" Alert ID: {alert.get('_id')}") logger.info(f" User: {alert.get('user_id')}") logger.info(f" Query: {alert.get('user_query')}") logger.info(f" Location: {alert.get('search_params', {}).get('location', 'Any')}") logger.info(f" Last Notified: {alert.get('last_notified_at', 'Never')}") logger.info(f" {'-'*60}") logger.info(f"{'='*60}\n") except Exception as e: logger.error(f"Failed to reset alerts: {e}") raise finally: await disconnect_db() if __name__ == "__main__": logger.info("Resetting alert notifications for testing...") asyncio.run(reset_alert_notifications())