예제 #1
0
    def _process_new(self, feed_item):
        """Creates a new campaign DCM object from a feed item representing a campaign from the Bulkdozer feed.

    This function simply creates the object to be inserted later by the BaseDAO
    object.

    Args:
      feed_item: Feed item representing the campaign from the Bulkdozer feed.

    Returns:
      A campaign object ready to be inserted in DCM through the API.

    """
        lp = self.landing_page_dao.get(feed_item, required=True)

        feed_item[FieldMap.CAMPAIGN_LANDING_PAGE_ID] = lp['id']
        feed_item[FieldMap.CAMPAIGN_LANDING_PAGE_NAME] = lp['name']

        return {
            'advertiserId':
            feed_item.get(FieldMap.ADVERTISER_ID, None),
            'name':
            feed_item.get(FieldMap.CAMPAIGN_NAME, None),
            'startDate':
            StringExtensions.convertDateTimeStrToDateStr(
                feed_item.get(FieldMap.CAMPAIGN_START_DATE, None)),
            'endDate':
            StringExtensions.convertDateTimeStrToDateStr(
                feed_item.get(FieldMap.CAMPAIGN_END_DATE, None)),
            'defaultLandingPageId':
            lp['id']
        }
예제 #2
0
  def _process_update(self, item, feed_item):
    """Updates an ad based on the values from the feed.

    Args:
      item: Object representing the ad to be updated, this object is updated
        directly.
      feed_item: Feed item representing ad values from the Bulkdozer feed.
    """
    campaign = self._campaign_dao.get(feed_item, required=True)

    item['active'] = feed_item.get(FieldMap.AD_ACTIVE, True)

    if item['active']:
      self._wait_all_creative_activation(feed_item)

    self._setup_rotation_strategy(item['creativeRotation'], feed_item)

    if feed_item['creative_assignment']:
      item['creativeRotation']['creativeAssignments'] = []

    item['placementAssignments'] = []
    item['eventTagOverrides'] = []

    self._process_assignments(
        feed_item, item['creativeRotation'].get('creativeAssignments', []),
        item['placementAssignments'], item['eventTagOverrides'], campaign)

    if 'deliverySchedule' in item:
      item['deliverySchedule']['priority'] = feed_item.get(
          FieldMap.AD_PRIORITY, None)

    if feed_item.get(FieldMap.AD_HARDCUTOFF, None) != None:
      if not 'deliverySchedule' in item:
        item['deliverySchedule'] = {}

      item['deliverySchedule']['hardCutoff'] = feed_item.get(
          FieldMap.AD_HARDCUTOFF)

    item['archived'] = feed_item.get(FieldMap.AD_ARCHIVED, False)

    if 'T' in feed_item.get(FieldMap.AD_END_DATE, None):
      item['endTime'] = feed_item.get(FieldMap.AD_END_DATE, None)
    else:
      item['endTime'] = StringExtensions.convertDateStrToDateTimeStr(
          feed_item.get(FieldMap.AD_END_DATE, None), '23:59:59')

    if 'T' in feed_item.get(FieldMap.AD_START_DATE, None):
      item['startTime'] = feed_item.get(FieldMap.AD_START_DATE, None)
    else:
      item['startTime'] = StringExtensions.convertDateStrToDateTimeStr(
          feed_item.get(FieldMap.AD_START_DATE, None))

    item['name'] = feed_item.get(FieldMap.AD_NAME, None)

    self._process_landing_page(item, feed_item)
예제 #3
0
    def _process_update(self, item, feed_item):
        """Updates a campaign based on the values from the feed.

    Args:
      item: Object representing the campaign to be updated, this object is
        updated directly.
      feed_item: Feed item representing campaign values from the Bulkdozer feed.
    """
        lp = self.landing_page_dao.get(feed_item, required=True)

        feed_item[FieldMap.CAMPAIGN_LANDING_PAGE_ID] = lp['id']
        feed_item[FieldMap.CAMPAIGN_LANDING_PAGE_NAME] = lp['name']

        item['startDate'] = StringExtensions.convertDateTimeStrToDateStr(
            feed_item.get(FieldMap.CAMPAIGN_START_DATE, None))
        item['endDate'] = StringExtensions.convertDateTimeStrToDateStr(
            feed_item.get(FieldMap.CAMPAIGN_END_DATE, None))
        item['name'] = feed_item.get(FieldMap.CAMPAIGN_NAME, None)
        item['defaultLandingPageId'] = lp['id']
예제 #4
0
  def _process_new(self, feed_item):
    """Creates a new ad DCM object from a feed item representing an ad from the Bulkdozer feed.

    This function simply creates the object to be inserted later by the BaseDAO
    object.

    Args:
      feed_item: Feed item representing the ad from the Bulkdozer feed.

    Returns:
      An ad object ready to be inserted in DCM through the API.

    """
    if feed_item.get(FieldMap.AD_ACTIVE, None):
      self._wait_all_creative_activation(feed_item)

    campaign = self._campaign_dao.get(feed_item, required=True)

    creative_assignments = []
    placement_assignments = []
    event_tag_assignments = []
    self._process_assignments(feed_item, creative_assignments,
                              placement_assignments, event_tag_assignments,
                              campaign)

    creative_rotation = {'creativeAssignments': creative_assignments}

    self._setup_rotation_strategy(creative_rotation, feed_item)

    delivery_schedule = {
        'impressionRatio': '1',
        'priority': feed_item.get(FieldMap.AD_PRIORITY, None),
        'hardCutoff': feed_item.get(FieldMap.AD_HARDCUTOFF, None)
    }

    ad = {
        'active':
            feed_item.get(FieldMap.AD_ACTIVE, None),
        'archived':
            feed_item.get(FieldMap.AD_ARCHIVED, None),
        'campaignId':
            campaign['id'],
        'creativeRotation':
            creative_rotation,
        'deliverySchedule':
            delivery_schedule,
        'endTime':
            feed_item.get(FieldMap.AD_END_DATE, None) if 'T' in feed_item.get(
                FieldMap.AD_END_DATE, None) else
            StringExtensions.convertDateStrToDateTimeStr(
                feed_item.get(FieldMap.AD_END_DATE, None), '23:59:59'),
        'name':
            feed_item.get(FieldMap.AD_NAME, None),
        'placementAssignments':
            placement_assignments,
        'startTime':
            feed_item.get(FieldMap.AD_START_DATE, None) if 'T' in feed_item.get(
                FieldMap.AD_START_DATE, None) else
            StringExtensions.convertDateStrToDateTimeStr(
                feed_item.get(FieldMap.AD_START_DATE, None)),
        'type':
            feed_item.get(FieldMap.AD_TYPE, 'AD_SERVING_STANDARD_AD'),
        'eventTagOverrides':
            event_tag_assignments
    }

    self._process_landing_page(ad, feed_item)

    return ad
예제 #5
0
  def _process_assignments(self, feed_item, creative_assignments,
                           placement_assignments, event_tag_assignments,
                           campaign):
    """Updates the ad by setting the values of child objects based on secondary feeds.

    Args:
      feed_item: Feed item representing the ad from the Bulkdozer feed.
      creative_assignments: Feed items representing creative assignments related
        with the current ad.
      placement_assignments: Feed items representing placement assignments
        related with the current ad.
      event_tag_assignments: Feed items representing event tag assignments
        related with the current ad.
    """
    assigned_creatives = []
    assigned_placements = []
    assigned_event_tags = []

    for assignment in feed_item['creative_assignment']:
      creative = self._creative_dao.get(assignment, required=True)
      assignment[FieldMap.CREATIVE_ID] = creative['id']

      if not creative['id'] in assigned_creatives:
        assigned_creatives.append(creative['id'])

        sequence = assignment.get(FieldMap.CREATIVE_ROTATION_SEQUENCE, None)
        weight = assignment.get(FieldMap.CREATIVE_ROTATION_WEIGHT, None)

        sequence = sequence if type(sequence) is int else None
        weight = weight if type(weight) is int else None

        if assignment.get(FieldMap.AD_CREATIVE_ROTATION_START_TIME, ''):
          startTime = (
              assignment.get(FieldMap.AD_CREATIVE_ROTATION_START_TIME,
                             '') if 'T' in assignment.get(
                                 FieldMap.AD_CREATIVE_ROTATION_START_TIME, '')
              else StringExtensions.convertDateStrToDateTimeStr(
                  feed_item.get(FieldMap.AD_CREATIVE_ROTATION_START_TIME,
                                None)))
          assignment[FieldMap.AD_CREATIVE_ROTATION_START_TIME] = startTime
        else:
          startTime = None

        if assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, ''):
          endTime = (
              assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, '') if
              'T' in assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, '')
              else StringExtensions.convertDateStrToDateTimeStr(
                  feed_item.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, None),
                  '23:59:59'))
          assignment[FieldMap.AD_CREATIVE_ROTATION_END_TIME] = endTime
        else:
          endTime = None

        lp = None
        if assignment.get(FieldMap.AD_LANDING_PAGE_ID,
                          '') != 'CAMPAIGN_DEFAULT':
          lp = self._landing_page_dao.get(assignment, required=True)
        else:
          lp = self._landing_page_dao.get(
              {FieldMap.AD_LANDING_PAGE_ID: campaign['defaultLandingPageId']},
              required=True)

        creative_assignment = {
            'active': True,
            'sequence': sequence,
            'weight': weight,
            'creativeId': assignment.get(FieldMap.CREATIVE_ID, None),
            'startTime': startTime,
            'endTime': endTime,
            'clickThroughUrl': {
                'defaultLandingPage':
                    False if
                    (assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or
                     assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')) and
                    assignment.get(FieldMap.AD_LANDING_PAGE_ID,
                                   '') != 'CAMPAIGN_DEFAULT' else True,
                'landingPageId':
                    lp.get('id', None) if lp else None,
                'customClickThroughUrl':
                    assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')
            }
        }

        if creative.get('exitCustomEvents'):
          creative_assignment['richMediaExitOverrides'] = []

          if assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or assignment.get(
              FieldMap.CUSTOM_CLICK_THROUGH_URL, ''):
            for exit_custom_event in creative.get('exitCustomEvents', []):
              creative_assignment['richMediaExitOverrides'].append({
                  'exitId': exit_custom_event['id'],
                  'enabled': True,
                  'clickThroughUrl': {
                      'defaultLandingPage':
                          False if
                          (assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or
                           assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')
                          ) and assignment.get(FieldMap.AD_LANDING_PAGE_ID, '')
                          != 'CAMPAIGN_DEFAULT' else True,
                      'landingPageId':
                          lp.get('id', None) if lp else None,
                      'customClickThroughUrl':
                          assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')
                  }
              })

        creative_assignments.append(creative_assignment)

    for assignment in feed_item['placement_assignment']:
      placement = self._placement_dao.get(assignment, required=True)
      if placement:
        assignment[FieldMap.PLACEMENT_ID] = placement['id']

        if not placement['id'] in assigned_placements:
          assigned_placements.append(placement['id'])

          placement_assignments.append({
              'active': True,
              'placementId': assignment.get(FieldMap.PLACEMENT_ID, None),
          })

    event_tags = [{
        'assignment': item,
        'event_tag': self._event_tag_dao.get(item, required=True)
    } for item in feed_item['event_tag_assignment']]

    event_tags += [{
        'assignment': item,
        'event_tag': self._event_tag_dao.get(item, required=True)
    } for item in feed_item['placement_event_tag_profile']]

    for item in event_tags:
      assignment = item['assignment']
      event_tag = item['event_tag']

      if event_tag:
        assignment[FieldMap.EVENT_TAG_ID] = event_tag['id']

        if not event_tag['id'] in assigned_event_tags:
          assigned_event_tags.append(event_tag['id'])

          event_tag_assignments.append({
              'id': event_tag['id'],
              'enabled': assignment.get(FieldMap.EVENT_TAG_ENABLED, True)
          })
예제 #6
0
    def _process_new(self, feed_item):
        """Creates a new placement DCM object from a feed item representing an placement from the Bulkdozer feed.

    This function simply creates the object to be inserted later by the BaseDAO
    object.

    Args:
      feed_item: Feed item representing the placement from the Bulkdozer feed.

    Returns:
      An placement object ready to be inserted in DCM through the API.

    """
        campaign = self.campaign_dao.get(feed_item, required=True)
        placement_group = self.placement_group_dao.get(feed_item,
                                                       required=True)

        feed_item[FieldMap.CAMPAIGN_ID] = campaign['id']
        feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name']

        if placement_group:
            feed_item[FieldMap.PLACEMENT_GROUP_ID] = placement_group['id']
            feed_item[FieldMap.PLACEMENT_GROUP_NAME] = placement_group['name']

        result = {
            'name':
            feed_item.get(FieldMap.PLACEMENT_NAME, None),
            'adBlockingOptOut':
            feed_item.get(FieldMap.PLACEMENT_AD_BLOCKING, False),
            'campaignId':
            campaign['id'],
            'placementGroupId':
            placement_group['id'] if placement_group else None,
            'archived':
            feed_item.get(FieldMap.PLACEMENT_ARCHIVED, False),
            'siteId':
            feed_item.get(FieldMap.SITE_ID, None),
            'paymentSource':
            'PLACEMENT_AGENCY_PAID',
            'pricingSchedule': {
                'startDate':
                StringExtensions.convertDateTimeStrToDateStr(
                    feed_item.get(FieldMap.PLACEMENT_START_DATE, None)),
                'endDate':
                StringExtensions.convertDateTimeStrToDateStr(
                    feed_item.get(FieldMap.PLACEMENT_END_DATE, None)),
                'pricingType':
                feed_item.get(
                    FieldMap.PLACEMENT_PRICING_SCHEDULE_COST_STRUCTURE, None)
                or 'PRICING_TYPE_CPM',
                'pricingPeriods': [{
                    'startDate':
                    feed_item.get(FieldMap.PLACEMENT_START_DATE, None),
                    'endDate':
                    feed_item.get(FieldMap.PLACEMENT_END_DATE, None)
                }]
            }
        }

        self._process_skipability(feed_item, result)

        if feed_item.get(FieldMap.PLACEMENT_ADDITIONAL_KEY_VALUES, None):
            result['tagSetting'] = {
                'additionalKeyValues':
                feed_item.get(FieldMap.PLACEMENT_ADDITIONAL_KEY_VALUES, None)
            }

        if feed_item.get(FieldMap.PLACEMENT_PRICING_TESTING_START, None):
            result['pricingSchedule']['testingStartDate'] = feed_item.get(
                FieldMap.PLACEMENT_PRICING_TESTING_START, None)

        self._process_active_view_and_verification(result, feed_item)

        if feed_item.get(FieldMap.PLACEMENT_TYPE,
                         None) == 'VIDEO' or feed_item[
                             FieldMap.PLACEMENT_TYPE] == 'IN_STREAM_VIDEO':
            result['compatibility'] = 'IN_STREAM_VIDEO'
            result['size'] = {'width': '0', 'height': '0'}
            result['tagFormats'] = ['PLACEMENT_TAG_INSTREAM_VIDEO_PREFETCH']
        elif feed_item[FieldMap.PLACEMENT_TYPE] == 'IN_STREAM_AUDIO':
            result['compatibility'] = 'IN_STREAM_AUDIO'
            result['size'] = {'width': '0', 'height': '0'}
            result['tagFormats'] = ['PLACEMENT_TAG_INSTREAM_VIDEO_PREFETCH']
        else:
            result['compatibility'] = 'DISPLAY'
            width = 1
            height = 1
            raw_size = feed_item.get(FieldMap.ASSET_SIZE, '0x0')
            if (raw_size and 'x' in raw_size):
                width, height = raw_size.strip().lower().split('x')

            sizes = self.get_sizes(int(width), int(height))

            if sizes:
                result['size'] = {'id': sizes[0]['id']}
            else:
                result['size'] = {'width': int(width), 'height': int(height)}

            result['tagFormats'] = [
                'PLACEMENT_TAG_STANDARD', 'PLACEMENT_TAG_JAVASCRIPT',
                'PLACEMENT_TAG_IFRAME_JAVASCRIPT',
                'PLACEMENT_TAG_IFRAME_ILAYER',
                'PLACEMENT_TAG_INTERNAL_REDIRECT', 'PLACEMENT_TAG_TRACKING',
                'PLACEMENT_TAG_TRACKING_IFRAME',
                'PLACEMENT_TAG_TRACKING_JAVASCRIPT'
            ]

        self._process_transcode(result, feed_item)
        self._process_pricing_schedule(result, feed_item)

        return result
예제 #7
0
    def _process_update(self, item, feed_item):
        """Updates an placement based on the values from the feed.

    Args:
      item: Object representing the placement to be updated, this object is
        updated directly.
      feed_item: Feed item representing placement values from the Bulkdozer
        feed.
    """

        if feed_item.get(FieldMap.CAMPAIGN_ID, '') == '':
            feed_item[FieldMap.CAMPAIGN_ID] = item['campaignId']

        campaign = self.campaign_dao.get(feed_item, required=True)
        placement_group = self.placement_group_dao.get(feed_item,
                                                       required=True)

        feed_item[FieldMap.CAMPAIGN_ID] = campaign['id']
        feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name']

        if placement_group:
            feed_item[FieldMap.PLACEMENT_GROUP_ID] = placement_group['id']
            feed_item[FieldMap.PLACEMENT_GROUP_NAME] = placement_group['name']
            item['placementGroupId'] = placement_group['id']
        else:
            item['placementGroupId'] = None

        self._process_skipability(feed_item, item)

        item['pricingSchedule']['startDate'] = (
            StringExtensions.convertDateTimeStrToDateStr(
                feed_item.get(FieldMap.PLACEMENT_START_DATE, None))
            if feed_item.get(FieldMap.PLACEMENT_START_DATE,
                             '') else item['pricingSchedule']['startDate'])

        item['pricingSchedule']['endDate'] = (
            StringExtensions.convertDateTimeStrToDateStr(
                feed_item.get(FieldMap.PLACEMENT_END_DATE, None))
            if feed_item.get(FieldMap.PLACEMENT_END_DATE,
                             '') else item['pricingSchedule']['endDate'])

        item['pricingSchedule']['pricingType'] = feed_item.get(
            FieldMap.PLACEMENT_PRICING_SCHEDULE_COST_STRUCTURE,
            None) if feed_item.get(
                FieldMap.PLACEMENT_PRICING_SCHEDULE_COST_STRUCTURE,
                '') else item['pricingSchedule']['pricingType']

        if feed_item.get(FieldMap.PLACEMENT_PRICING_TESTING_START, None):
            item['pricingSchedule']['testingStartDate'] = feed_item.get(
                FieldMap.PLACEMENT_PRICING_TESTING_START, None)

        item['name'] = feed_item.get(
            FieldMap.PLACEMENT_NAME, None) if feed_item.get(
                FieldMap.PLACEMENT_NAME, '') else item['name']
        item['archived'] = feed_item.get(
            FieldMap.PLACEMENT_ARCHIVED, None) if feed_item.get(
                FieldMap.PLACEMENT_ARCHIVED, '') else item['archived']
        item['adBlockingOptOut'] = feed_item.get(
            FieldMap.PLACEMENT_AD_BLOCKING, False)

        self._process_transcode(item, feed_item)
        self._process_active_view_and_verification(item, feed_item)
        self._process_pricing_schedule(item, feed_item)

        key_values = feed_item.get(FieldMap.PLACEMENT_ADDITIONAL_KEY_VALUES,
                                   None)
        if key_values == '':
            if item.get('tagSetting', {}).get('additionalKeyValues'):
                del item['tagSetting']['additionalKeyValues']
        elif key_values != None:
            if not 'tagSetting' in item:
                item['tagSetting'] = {}

            item['tagSetting']['additionalKeyValues'] = key_values