from datetime import datetime from audience_common.owsclient import OwsClient from dmp_workflows import config from dmp_workflows.config import EASTERN_TZ from dmp_workflows.hooks.auth import m2m_token_manager from dmp_workflows.hooks.clients.ows_notifications import ( AudienceDeletedFansReportNotificationArgs, OwsNotificationsClient, ) class EmailHook: @classmethod def send_fans_deleted_report(cls, fans_count: int) -> bool: """ Send email to the given email address. """ ows_client = OwsClient( environment=config.OWS_ENV, service_name=config.SERVICE_NAME, m2m_token_manager=m2m_token_manager, ) ows_notifications_client = OwsNotificationsClient( ows_client=ows_client, ) email_args = AudienceDeletedFansReportNotificationArgs( deleted_fans_count=fans_count, date=datetime.now(tz=EASTERN_TZ).isoformat(), recipients=config.CRM_EMAILS, bcc_recipients=config.BCC_EMAILS, ) return ows_notifications_client.send_fans_deleted_report( args=email_args, )