Refactored code for export_notifications.py