def send_labour_hire_licence_expiry_campaign(client, sellers): folder_id = getenv('MAILCHIMP_MARKETPLACE_FOLDER_ID') if not folder_id: raise MailChimpConfigException( 'Failed to get MAILCHIMP_MARKETPLACE_FOLDER_ID from the environment variables.' ) list_id = getenv('MAILCHIMP_SELLER_LIST_ID') if not list_id: raise MailChimpConfigException( 'Failed to get MAILCHIMP_SELLER_LIST_ID from the environment variables.' ) title = 'Expiring labour hire licence - {}'.format( pendulum.today().to_date_string()) sent_expiring_licence_audit_event = audit_service.filter( AuditEvent.type == audit_types.sent_expiring_licence_email.value, AuditEvent.data['campaign_title'].astext == title).one_or_none() if (sent_expiring_licence_audit_event > 0): return conditions = [] for seller in sellers: for email_address in seller['email_addresses']: conditions.append({ 'condition_type': 'EmailAddress', 'op': 'is', 'field': 'EMAIL', 'value': email_address }) recipients = { 'list_id': list_id, 'segment_opts': { 'match': 'any', 'conditions': conditions } } settings = { 'folder_id': folder_id, 'preview_text': 'Please update your labour hire licence details', 'subject_line': 'Your labour hire licence details are soon to expire or have expired', 'title': title } campaign = create_campaign(client, recipients, settings) template = template_env.get_template('mailchimp_licence_expiry.html') email_body = template.render(current_year=pendulum.today().year) update_campaign_content(client, campaign['id'], email_body) schedule_campaign( client, campaign['id'], pendulum.now('Australia/Sydney').at(10, 0, 0).in_timezone('UTC')) audit_service.log_audit_event( audit_type=audit_types.sent_expiring_licence_email, data={ 'campaign_title': title, 'sellers': sellers }, db_object=None, user=None)
def send_document_expiry_campaign(client, sellers): folder_id = getenv('MAILCHIMP_MARKETPLACE_FOLDER_ID') if not folder_id: raise MailChimpConfigException('Failed to get MAILCHIMP_MARKETPLACE_FOLDER_ID from the environment variables.') list_id = getenv('MAILCHIMP_SELLER_LIST_ID') if not list_id: raise MailChimpConfigException('Failed to get MAILCHIMP_SELLER_LIST_ID from the environment variables.') title = 'Expiring documents - {}'.format(pendulum.today().to_date_string()) sent_expiring_documents_audit_event = audit_service.filter( AuditEvent.type == audit_types.sent_expiring_documents_email.value, AuditEvent.data['campaign_title'].astext == title ).one_or_none() if (sent_expiring_documents_audit_event > 0): return conditions = [] for seller in sellers: for email_address in seller['email_addresses']: conditions.append({ 'condition_type': 'EmailAddress', 'op': 'is', 'field': 'EMAIL', 'value': email_address }) recipients = { 'list_id': list_id, 'segment_opts': { 'match': 'any', 'conditions': conditions } } settings = { 'folder_id': folder_id, 'preview_text': 'Please update your documents', 'subject_line': 'Your documents are soon to expire or have expired', 'title': title } campaign = create_campaign(client, recipients, settings) template = template_env.get_template('mailchimp_document_expiry.html') email_body = template.render(current_year=pendulum.today().year) update_campaign_content(client, campaign['id'], email_body) schedule_campaign(client, campaign['id'], pendulum.now('Australia/Sydney').at(10, 0, 0).in_timezone('UTC')) audit_service.log_audit_event( audit_type=audit_types.sent_expiring_documents_email, data={ 'campaign_title': title, 'sellers': sellers }, db_object=None, user=None )