Esempio n. 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']
        }
Esempio n. 2
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']
Esempio n. 3
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
Esempio n. 4
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