示例#1
0
  def create_event_finished_campaigns(self):
    finished_date = self.event.live_stop_date.replace(tzinfo = timezone(settings.TIME_ZONE))
    event_finished_time = self.gmt_timestamp(finished_date)

    mailchimp = MailChimp(settings.MAILCHIMP_API_KEY)
    self.campaign_sorry_id = mailchimp.campaignCreate(
        type = 'regular',
        content = {'html_mid_content00': self.event.description},
        segment_opts = {'match': 'all', 'conditions': [{
                              'field': 'static_segment',
                              'op': 'eq',
                              'value': self.participated_segment_id
                        }]},
        options = {
          'list_id': settings.MAILCHIMP_LIST_ID,
          'subject': settings.MAILCHIMP_SUBJECTS['finished_sorry_we_missed'],
          'from_email': settings.MAILCHIMP_FROM_EMAIL,
          'from_name': settings.MAILCHIMP_FROM_NAME,
          'to_email': settings.MAILCHIMP_TO_EMAIL,
          'template_id': self.event.template_missed_you,
        }
    )

    self.campaign_thanks_id = mailchimp.campaignCreate(
        type = 'regular',
        content = {'html_mid_content00': self.event.description},
        segment_opts = {'match': 'all', 'conditions': [
                            {
                              'field': 'static_segment',
                              'op': 'ne',
                              'value': self.participated_segment_id
                            },
                            {
                              'field': 'static_segment',
                              'op': 'eq',
                              'value': self.list_segment_id
                            }]},
        options = {
          'list_id': settings.MAILCHIMP_LIST_ID,
          'subject': settings.MAILCHIMP_SUBJECTS['finished_thank_you'],
          'from_email': settings.MAILCHIMP_FROM_EMAIL,
          'from_name': settings.MAILCHIMP_FROM_NAME,
          'to_email': settings.MAILCHIMP_TO_EMAIL,
          'template_id': self.event.template_thank_you,
        }
    )
    try:
      mailchimp.campaignSchedule(cid = self.campaign_thanks_id, schedule_time = event_finished_time)
      mailchimp.campaignSchedule(cid = self.campaign_sorry_id, schedule_time = event_finished_time)
    except MailChimpError as error:
      logger.error("Campaign scheduled in the past: %s" % error.msg)
示例#2
0
  def create_campaign(self, subject_format, schedule_time = None, time_str = None, template_id = None):
    mailchimp = MailChimp(settings.MAILCHIMP_API_KEY)
    campaign_id = mailchimp.campaignCreate(
        type = 'regular',
        content = {'html_mid_content00': self.event.description},
        segment_opts = {'match': 'all', 'conditions': [{
                              'field': 'static_segment',
                              'op': 'eq',
                              'value': self.list_segment_id
                        }]},
        options = {
          'list_id': settings.MAILCHIMP_LIST_ID,
          'subject': subject_format.format(event = self.event.name, time = time_str), 
          'from_email': settings.MAILCHIMP_FROM_EMAIL,
          'from_name': settings.MAILCHIMP_FROM_NAME,
          'to_email': settings.MAILCHIMP_TO_EMAIL,
          'template_id': template_id,
        }
    )

    if schedule_time != None:
      try:
        mailchimp.campaignSchedule(cid = campaign_id, schedule_time = schedule_time)
      except MailChimpError as error:
        logger.error("Campaign scheduled in the past: %s" % error.msg)

    return campaign_id
示例#3
0
 def dispatch_mailchimp(self):
     site = self.site
     social = site.social
     if social.mailchimp_send_blast != Social.CAMPAIGN_NO_CREATE:
         mailchimp = MailChimp(social.mailchimp_api_key)
         campaign_id = mailchimp.campaignCreate(
             type='regular',
             options={
                 'list_id': social.mailchimp_list_id,
                 'subject': self.title,
                 'from_email': social.mailchimp_from_email,
                 'from_name': site.name,
                 'to_name': '%s subscribers' % site.name,
             },
             content={
                 'html': self.get_body_html(),
                 'text': self.get_body_text()
         })
         if social.mailchimp_send_blast == Social.CAMPAIGN_SEND:
             mailchimp.campaignSendNow(cid=campaign_id)
         data_center = social.mailchimp_api_key.split('-')[1]
         Release.objects.filter(id=self.id).update(
             mailchimp = 'http://%s.admin.mailchimp.com/campaigns/show?id=%s' % (data_center, campaign_id)
         )