Exemplo n.º 1
0
class BulkCampaignProductScope(_SingleRecordBulkEntity):
    """ Represents a Campaign Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`campaign_criterion` property that can be read and written as fields of the
    Campaign Product Scope record in a bulk file.

    For more information, see Campaign Product Scope at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 campaign_name=None,
                 status=None,
                 biddable_campaign_criterion=None):
        super(BulkCampaignProductScope, self).__init__()

        self._campaign_name = campaign_name
        self._status = status
        self._biddable_campaign_criterion = biddable_campaign_criterion

    @classmethod
    def _add_product_condition_to_row_values(cls, entity, value):
        criterion = entity.biddable_campaign_criterion.Criterion
        if criterion is not None and hasattr(criterion, 'Conditions') and criterion.Conditions is not None and \
                hasattr(criterion.Conditions, 'ProductCondition'):
            return _ProductConditionHelper.add_row_values_from_conditions(
                criterion.Conditions.ProductCondition, value)
        return None

    _MAPPINGS = [
        _SimpleBulkMapping(
            _StringTable.Status,
            field_to_csv=lambda c: c.biddable_campaign_criterion.Status,
            csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion,
                                              'Status', v)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.CampaignId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'CampaignId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _ComplexBulkMapping(entity_to_csv=lambda c, v: BulkCampaignProductScope
                            ._add_product_condition_to_row_values(c, v),
                            csv_to_entity=lambda v, c: _ProductConditionHelper.
                            add_conditions_from_row_values(
                                v, c.biddable_campaign_criterion.Criterion.
                                Conditions.ProductCondition))
    ]

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def status(self):
        """ The status of the Campaign Criterion

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def biddable_campaign_criterion(self):
        """ Defines a Biddable Campaign Criterion """

        return self._biddable_campaign_criterion

    @biddable_campaign_criterion.setter
    def biddable_campaign_criterion(self, biddable_campaign_criterion):
        self._biddable_campaign_criterion = biddable_campaign_criterion

    def process_mappings_from_row_values(self, row_values):
        self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'BiddableCampaignCriterion')
        self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion'
        self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'ProductScope')
        self._biddable_campaign_criterion.Criterion.Type = 'ProductScope'

        row_values.convert_to_entity(self, BulkCampaignProductScope._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_campaign_criterion,
                                         'biddable_campaign_criterion')
        self.convert_to_values(row_values, BulkCampaignProductScope._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignProductScope,
              self).read_additional_data(stream_reader)
Exemplo n.º 2
0
class BulkKeyword(_SingleRecordBulkEntity):
    """ Represents a keyword that can be read or written in a bulk file.

    This class exposes the :attr:`keyword` property that can be read and written as fields of the Keyword record in a bulk file.
    Properties of this class and of classes that it is derived from, correspond to fields of the Keyword record in a bulk file.
    For more information, see Keyword at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self, ad_group_id=None, campaign_name=None, ad_group_name=None, keyword=None):
        super(BulkKeyword, self).__init__()
        self._ad_group_id = ad_group_id
        self._keyword = keyword
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._quality_score_data = None
        self._bid_suggestions = None

    @property
    def ad_group_id(self):
        """ The identifier of the ad group that contains the keyword.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._ad_group_id

    @ad_group_id.setter
    def ad_group_id(self, ad_group_id):
        self._ad_group_id = ad_group_id

    @property
    def keyword(self):
        """ Defines a keyword within an ad group.

        See Keyword at https://docs.microsoft.com/en-us/bingads/campaign-management-service/keyword?view=bingads-13
        """

        return self._keyword

    @keyword.setter
    def keyword(self, keyword):
        self._keyword = keyword

    @property
    def campaign_name(self):
        """ The name of the campaign that contains the keyword.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the ad group that contains the keyword.

        Corresponds to the 'Ad Group' field in the bulk file.

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def quality_score_data(self):
        """ The quality score data for the keyword.

        :rtype: QualityScoreData
        """

        return self._quality_score_data

    @property
    def bid_suggestions(self):
        """ The bid suggestion data for the keyword.

        :rtype: BidSuggestionData
        """

        return self._bid_suggestions

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.keyword.Status),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Status',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Id',
                int(v) if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_group_id),
            csv_to_field=lambda c, v: setattr(
                c,
                '_ad_group_id',
                int(v) if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, '_campaign_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Keyword,
            field_to_csv=lambda c: c.keyword.Text,
            csv_to_field=lambda c, v: setattr(c.keyword, 'Text', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EditorialStatus,
            field_to_csv=lambda c: bulk_str(c.keyword.EditorialStatus),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'EditorialStatus',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.MatchType,
            field_to_csv=lambda c: bulk_str(c.keyword.MatchType),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'MatchType',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.DestinationUrl,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.DestinationUrl, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'DestinationUrl',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Bid,
            field_to_csv=lambda c: keyword_bid_bulk_str(c.keyword.Bid, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Bid',
                parse_keyword_bid(v)
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param1,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param1, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param1',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param2,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param2, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param2',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param3,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param3, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param3',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalUrls, c.keyword.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalMobileUrls, c.keyword.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalMobileUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.keyword.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.keyword, 'TrackingUrlTemplate', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.keyword),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.keyword, v)
        ),
        _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.FinalUrlSuffix, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(c.keyword, 'FinalUrlSuffix', v)
        ),
    ]

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self._keyword, 'keyword')
        self.convert_to_values(row_values, BulkKeyword._MAPPINGS)
        if not exclude_readonly_data:
            QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values)

    def process_mappings_from_row_values(self, row_values):
        self._keyword = _CAMPAIGN_OBJECT_FACTORY_V13.create('Keyword')
        row_values.convert_to_entity(self, BulkKeyword._MAPPINGS)
        self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values)

    def read_additional_data(self, stream_reader):
        success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion)

        while success:
            if self._bid_suggestions is None:
                self._bid_suggestions = BidSuggestionData()

            if isinstance(next_bid_suggestion, BulkKeywordBestPositionBid):
                self._bid_suggestions.best_position = next_bid_suggestion
            elif isinstance(next_bid_suggestion, BulkKeywordMainLineBid):
                self._bid_suggestions.main_line = next_bid_suggestion
            elif isinstance(next_bid_suggestion, BulkKeywordFirstPageBid):
                self._bid_suggestions.first_page = next_bid_suggestion

            success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion)

    def write_additional_data(self, row_writer):
        if self.bid_suggestions is not None:
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.best_position, row_writer)
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.main_line, row_writer)
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.first_page, row_writer)
class BulkAdGroupDynamicSearchAdTarget(_SingleRecordBulkEntity):
    """ Represents a Ad Group Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the
    Ad Group Dynamic Search Ad Target record in a bulk file.

    For more information, see Ad Group Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836837.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 campaign_name=None,
                 ad_group_name=None,
                 status=None,
                 biddable_ad_group_criterion=None):
        super(BulkAdGroupDynamicSearchAdTarget, self).__init__()

        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._status = status
        self._biddable_ad_group_criterion = biddable_ad_group_criterion
        self._performance_data = None

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_ad_group_criterion.AdGroupId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'AdGroupId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)),
        _SimpleBulkMapping(header=_StringTable.Bid,
                           field_to_csv=lambda c: fixed_bid_bulk_str(
                               c.biddable_ad_group_criterion.CriterionBid),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'CriterionBid',
                               parse_fixed_bid(v))),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v:
            csv_to_field_WebpageParameter_CriterionName(
                c.biddable_ad_group_criterion, v)),
        _ComplexBulkMapping(
            entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(
                c.biddable_ad_group_criterion, v),
            csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(
                v, c.biddable_ad_group_criterion)),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_optional_str(
                c.biddable_ad_group_criterion.TrackingUrlTemplate, c.
                biddable_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'TrackingUrlTemplate', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(
                c.biddable_ad_group_criterion, v)),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(
                c.biddable_ad_group_criterion.FinalUrlSuffix, c.
                biddable_ad_group_criterion.Id)
            if isinstance(c.biddable_ad_group_criterion,
                          _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'FinalUrlSuffix', v)
            if isinstance(c.biddable_ad_group_criterion,
                          _BiddableAdGroupCriterion) else None)
    ]

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def status(self):
        """ The status of the Ad Group Criterion

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def biddable_ad_group_criterion(self):
        """ Defines a Ad Group Criterion """

        return self._biddable_ad_group_criterion

    @biddable_ad_group_criterion.setter
    def biddable_ad_group_criterion(self, biddable_ad_group_criterion):
        self._biddable_ad_group_criterion = biddable_ad_group_criterion

    def process_mappings_from_row_values(self, row_values):
        self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'BiddableAdGroupCriterion')
        self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'
        self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'Webpage')
        self._biddable_ad_group_criterion.Criterion.Type = 'Webpage'
        self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'FixedBid')
        self._biddable_ad_group_criterion.CriterionBid.Type = 'FixedBid'

        row_values.convert_to_entity(
            self, BulkAdGroupDynamicSearchAdTarget._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_ad_group_criterion,
                                         'biddable_ad_group_criterion')
        self.convert_to_values(row_values,
                               BulkAdGroupDynamicSearchAdTarget._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupDynamicSearchAdTarget,
              self).read_additional_data(stream_reader)
Exemplo n.º 4
0
class BulkAdGroup(_SingleRecordBulkEntity):
    """ Represents an ad group.

    This class exposes the property :attr:`ad_group` that can be read and written as fields of the Ad Group record
    in a bulk file.

    For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, campaign_id=None, campaign_name=None, ad_group=None):
        super(BulkAdGroup, self).__init__()

        self._campaign_id = campaign_id
        self._campaign_name = campaign_name
        self._ad_group = ad_group

        self._quality_score_data = None
        self._performance_data = None

    @property
    def campaign_id(self):
        """ The identifier of the campaign that contains the ad group.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._campaign_id

    @campaign_id.setter
    def campaign_id(self, campaign_id):
        self._campaign_id = campaign_id

    @property
    def campaign_name(self):
        """ The name of the campaign that contains the ad group.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group(self):
        """ The AdGroup Data Object of the Campaign Management Service.

        A subset of AdGroup properties are available in the Ad Group record.
        For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127.
        """
        return self._ad_group

    @ad_group.setter
    def ad_group(self, ad_group):
        self._ad_group = ad_group

    @property
    def quality_score_data(self):
        """ The quality score data for the ad group.

        :rtype: QualityScoreData
        """
        return self._quality_score_data

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_group.Id),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(c.ad_group.Status),
                           csv_to_field=csv_to_status),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.campaign_id),
            csv_to_field=lambda c, v: setattr(c, 'campaign_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group.Name,
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Name', v)),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: bulk_date_str(c.ad_group.StartDate),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'StartDate',
                                              parse_date(v))),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: bulk_date_str(c.ad_group.EndDate),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'EndDate',
                                              parse_date(v))),
        _SimpleBulkMapping(
            header=_StringTable.NetworkDistribution,
            field_to_csv=lambda c: bulk_str(c.ad_group.Network),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Network', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.AdRotation,
            field_to_csv=lambda c: ad_rotation_bulk_str(
                c.ad_group.AdRotation, c.ad_group.Id),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'AdRotation',
                                              parse_ad_rotation(v))),
        _SimpleBulkMapping(
            header=_StringTable.CpcBid,
            field_to_csv=lambda c: ad_group_bid_bulk_str(c.ad_group.CpcBid),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'CpcBid',
                                              parse_ad_group_bid(v))),
        _SimpleBulkMapping(
            header=_StringTable.Language,
            field_to_csv=lambda c: bulk_str(c.ad_group.Language),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Language', v
                                              if v else None)),
        _SimpleBulkMapping(header=_StringTable.BidAdjustment,
                           field_to_csv=lambda c: bulk_str(
                               c.ad_group.AudienceAdsBidAdjustment),
                           csv_to_field=lambda c, v: setattr(
                               c.ad_group, 'AudienceAdsBidAdjustment',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.ad_group.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(
                c.ad_group, 'TrackingUrlTemplate', v if v else None)),
        _SimpleBulkMapping(header=_StringTable.CustomParameter,
                           field_to_csv=lambda c:
                           field_to_csv_UrlCustomParameters(c.ad_group),
                           csv_to_field=lambda c, v:
                           csv_to_field_UrlCustomParameters(c.ad_group, v)),
        _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),
        _SimpleBulkMapping(
            header=_StringTable.TargetSetting,
            field_to_csv=lambda c: target_setting_to_csv(c.ad_group),
            csv_to_field=lambda c, v: csv_to_target_setting(c.ad_group, v)),
        _SimpleBulkMapping(
            header=_StringTable.PrivacyStatus,
            field_to_csv=lambda c: bulk_str(c.ad_group.PrivacyStatus),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'PrivacyStatus', v
                                              if v else None)),
        _ComplexBulkMapping(coop_setting_to_csv, csv_to_coop_setting),
        _SimpleBulkMapping(header=_StringTable.FinalUrlSuffix,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.ad_group.FinalUrlSuffix, c.ad_group.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.ad_group, 'FinalUrlSuffix', v)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.ad_group = _CAMPAIGN_OBJECT_FACTORY_V13.create('AdGroup')

        row_values.convert_to_entity(self, BulkAdGroup._MAPPINGS)

        self._quality_score_data = QualityScoreData.read_from_row_values_or_null(
            row_values)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self._ad_group, 'AdGroup')
        self.convert_to_values(row_values, BulkAdGroup._MAPPINGS)
        if not exclude_readonly_data:
            QualityScoreData.write_to_row_values_if_not_null(
                self.quality_score_data, row_values)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroup, self).read_additional_data(stream_reader)
Exemplo n.º 5
0
class BulkCampaignNegativeDynamicSearchAdTarget(_SingleRecordBulkEntity):
    """ Represents a Campaign Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`negative_campaign_criterion` property that can be read and written as fields of the
    Campaign Negative Dynamic Search Ad Target record in a bulk file.

    For more information, see Campaign Negative Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836839.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 campaign_name=None,
                 status=None,
                 negative_campaign_criterion=None):
        super(BulkCampaignNegativeDynamicSearchAdTarget, self).__init__()

        self._campaign_name = campaign_name
        self._status = status
        self._negative_campaign_criterion = negative_campaign_criterion

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.negative_campaign_criterion.CampaignId),
                           csv_to_field=lambda c, v: setattr(
                               c.negative_campaign_criterion, 'CampaignId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(
                c.negative_campaign_criterion),
            csv_to_field=lambda c, v:
            csv_to_field_WebpageParameter_CriterionName(
                c.negative_campaign_criterion, v)),
        _ComplexBulkMapping(
            entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(
                c.negative_campaign_criterion, v),
            csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(
                v, c.negative_campaign_criterion))
    ]

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def status(self):
        """ The status of the Campaign Criterion

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def negative_campaign_criterion(self):
        """ Defines a Campaign Criterion """

        return self._negative_campaign_criterion

    @negative_campaign_criterion.setter
    def negative_campaign_criterion(self, negative_campaign_criterion):
        self._negative_campaign_criterion = negative_campaign_criterion

    def process_mappings_from_row_values(self, row_values):
        self._negative_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'NegativeCampaignCriterion')
        self._negative_campaign_criterion.Type = 'NegativeCampaignCriterion'
        self._negative_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'Webpage')
        self._negative_campaign_criterion.Criterion.Type = 'Webpage'

        row_values.convert_to_entity(
            self, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.negative_campaign_criterion,
                                         'negative_campaign_criterion')
        self.convert_to_values(
            row_values, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignNegativeDynamicSearchAdTarget,
              self).read_additional_data(stream_reader)
Exemplo n.º 6
0
class BulkAdGroupProductPartition(_SingleRecordBulkEntity):
    """ Represents an Ad Group Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`ad_group_criterion` property that can be read and written as fields of the
    Ad Group Product Partition record in a bulk file.

    For more information, see Ad Group Product Scope at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 ad_group_criterion=None,
                 campaign_name=None,
                 ad_group_name=None):
        super(BulkAdGroupProductPartition, self).__init__()

        self._ad_group_criterion = ad_group_criterion
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._performance_data = None

    @classmethod
    def _read_is_excluded(cls, entity, row_value):
        if row_value is None:
            row_value = ''
        row_value = row_value.lower()
        if row_value == 'yes' or row_value == 'true':
            is_excluded = True
        elif row_value == 'no' or row_value == 'false':
            is_excluded = False
        else:
            raise ValueError(
                'IsExcluded can only be set to TRUE|FALSE in Ad Group Product Partition row'
            )
        if is_excluded:
            product_partition = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'ProductPartition')
            product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'ProductCondition')
            product_partition.Type = 'ProductPartition'

            negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'NegativeAdGroupCriterion')
            negative_ad_group_criterion.Criterion = product_partition
            negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion'

            entity.ad_group_criterion = negative_ad_group_criterion
        else:
            product_partition = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'ProductPartition')
            product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'ProductCondition')
            product_partition.Type = 'ProductPartition'

            fixed_bid = _CAMPAIGN_OBJECT_FACTORY_V13.create('FixedBid')
            fixed_bid.Type = 'FixedBid'

            biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'BiddableAdGroupCriterion')
            biddable_ad_group_criterion.Criterion = product_partition
            biddable_ad_group_criterion.CriterionBid = fixed_bid
            biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'

            entity.ad_group_criterion = biddable_ad_group_criterion

    @classmethod
    def _write_bid(cls, entity):
        criterion = entity.ad_group_criterion
        if isinstance(criterion, _BiddableAdGroupCriterion) and \
                criterion.CriterionBid is not None:
            return fixed_bid_bulk_str(entity.ad_group_criterion.CriterionBid)

    @classmethod
    def _read_bid(cls, entity, row_value):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            entity.ad_group_criterion.CriterionBid = parse_fixed_bid(row_value)
        else:
            pass

    @classmethod
    def _write_destination_url(cls, entity):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            return entity.ad_group_criterion.DestinationUrl
        else:
            return None

    @classmethod
    def _get_partition_type(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'PartitionType'):
            return entity.ad_group_criterion.Criterion.PartitionType
        return None

    @classmethod
    def _get_parent_criterion_id(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'ParentCriterionId'):
            return bulk_str(
                entity.ad_group_criterion.Criterion.ParentCriterionId)
        return None

    @classmethod
    def _get_condition_operand(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \
                entity.ad_group_criterion.Criterion.Condition is not None and \
                hasattr(entity.ad_group_criterion.Criterion.Condition, 'Operand'):
            return entity.ad_group_criterion.Criterion.Condition.Operand
        return None

    @classmethod
    def _get_condition_attribute(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \
                entity.ad_group_criterion.Criterion.Condition is not None and \
                hasattr(entity.ad_group_criterion.Criterion.Condition, 'Attribute'):
            return entity.ad_group_criterion.Criterion.Condition.Attribute
        return None

    @classmethod
    def _read_destination_url(cls, entity, row_value):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            entity.ad_group_criterion.DestinationUrl = row_value
        else:
            pass

    _MAPPINGS = [
        _ComplexBulkMapping(bidding_to_csv, csv_to_bidding),
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: c.ad_group_criterion.Status,
                           csv_to_field=lambda c, v: setattr(
                               c.ad_group_criterion, 'Status', v)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_group_criterion.AdGroupId),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion,
                                              'AdGroupId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)),
        _SimpleBulkMapping(
            _StringTable.SubType,
            field_to_csv=lambda c: BulkAdGroupProductPartition.
            _get_partition_type(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion,
                                              'PartitionType', v)),
        _SimpleBulkMapping(
            _StringTable.ParentAdGroupCriterionId,
            field_to_csv=lambda c: BulkAdGroupProductPartition.
            _get_parent_criterion_id(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion,
                                              'ParentCriterionId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.ProductCondition1,
            field_to_csv=lambda c: BulkAdGroupProductPartition.
            _get_condition_operand(c),
            csv_to_field=lambda c, v: setattr(
                c.ad_group_criterion.Criterion.Condition, 'Operand', v)),
        _SimpleBulkMapping(
            _StringTable.ProductValue1,
            field_to_csv=lambda c: BulkAdGroupProductPartition.
            _get_condition_attribute(c),
            csv_to_field=lambda c, v: setattr(
                c.ad_group_criterion.Criterion.Condition, 'Attribute', v)),
        _SimpleBulkMapping(
            _StringTable.DestinationUrl,
            field_to_csv=lambda c: BulkAdGroupProductPartition.
            _write_destination_url(c),
            csv_to_field=lambda c, v: BulkAdGroupProductPartition.
            _read_destination_url(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(
                c.ad_group_criterion.FinalUrls, c.ad_group_criterion.Id)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None,
            csv_to_field=lambda c, v: csv_to_field_Urls(
                c.ad_group_criterion.FinalUrls, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(
                c.ad_group_criterion.FinalMobileUrls, c.ad_group_criterion.Id)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None,
            csv_to_field=lambda c, v: csv_to_field_Urls(
                c.ad_group_criterion.FinalMobileUrls, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None),
        _SimpleBulkMapping(header=_StringTable.TrackingTemplate,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.ad_group_criterion.TrackingUrlTemplate, c.
                               ad_group_criterion.Id)
                           if isinstance(c.ad_group_criterion,
                                         _BiddableAdGroupCriterion) else None,
                           csv_to_field=lambda c, v: setattr(
                               c.ad_group_criterion, 'TrackingUrlTemplate', v
                               if v else None)
                           if isinstance(c.ad_group_criterion,
                                         _BiddableAdGroupCriterion) else None),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(
                c.ad_group_criterion) if isinstance(
                    c.ad_group_criterion, _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(
                c.ad_group_criterion, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(
                c.ad_group_criterion.FinalUrlSuffix, c.ad_group_criterion.Id)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion
                          ) else None,
            csv_to_field=lambda c, v: setattr(
                c.ad_group_criterion, 'FinalUrlSuffix', v) if isinstance(
                    c.ad_group_criterion, _BiddableAdGroupCriterion) else None)
    ]

    @property
    def ad_group_criterion(self):
        """ Defines an Ad Group Criterion """

        return self._ad_group_criterion

    @ad_group_criterion.setter
    def ad_group_criterion(self, ad_group_criterion):
        self._ad_group_criterion = ad_group_criterion

    @property
    def campaign_name(self):
        """ Defines the name of the Campaign.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ Defines the name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.ad_group_criterion,
                                         'ad_group_criterion')
        self.convert_to_values(row_values,
                               BulkAdGroupProductPartition._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        row_values.convert_to_entity(self,
                                     BulkAdGroupProductPartition._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupProductPartition,
              self).read_additional_data(stream_reader)
Exemplo n.º 7
0
class BulkPriceAdExtension(_BulkAdExtensionBase):
    """ Represents a Price Ad Extension.

    This class exposes the :attr:`price_ad_extension` property that can be read and written
    as fields of the Price Ad Extension record in a bulk file.

    For more information, see Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self, account_id=None, ad_extension=None):
        if ad_extension and not isinstance(ad_extension, _PriceAdExtension):
            raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format(
                type(ad_extension),
                'PriceAdExtension'
            ))
        super(BulkPriceAdExtension, self).__init__(
            account_id=account_id,
            ad_extension=ad_extension
        )

    @property
    def price_ad_extension(self):
        """ The Price Ad Extension.

        see Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad_extension

    @price_ad_extension.setter
    def price_ad_extension(self, value):
        self._ad_extension = value


    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Language,
            field_to_csv=lambda c: c.price_ad_extension.Language,
            csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'Language', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.PriceExtensionType,
            field_to_csv=lambda c: c.price_ad_extension.PriceExtensionType,
            csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'PriceExtensionType', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.price_ad_extension.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'TrackingUrlTemplate', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.price_ad_extension),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.price_ad_extension, v)
        ),
        _ComplexBulkMapping(
            entity_to_csv=lambda c, v: entity_to_csv_PriceTableRows(c.price_ad_extension, v),
            csv_to_entity=lambda v, c: csv_to_entity_PriceTableRows(v, c.price_ad_extension)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(c.price_ad_extension.FinalUrlSuffix, c.price_ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'FinalUrlSuffix', v)
        )
    ]

    def process_mappings_from_row_values(self, row_values):
        self.price_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V13.create('PriceAdExtension')
        self.price_ad_extension.Type = 'PriceAdExtension'
        super(BulkPriceAdExtension, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkPriceAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.price_ad_extension, 'price_ad_extension')
        super(BulkPriceAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkPriceAdExtension._MAPPINGS)
Exemplo n.º 8
0
class BulkCampaign(_SingleRecordBulkEntity):
    """ Represents a campaign that can be read or written in a bulk file.

    This class exposes the :attr:`campaign` property that can be read and written as fields of the
    Campaign record in a bulk file.

    For more information, see Campaign at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, campaign=None):
        super(BulkCampaign, self).__init__()

        self._account_id = account_id
        self._campaign = campaign
        self._quality_score_data = None
        self._performance_data = None
        self._budget_name = None

    @property
    def account_id(self):
        """ The identifier of the account that contains the campaign.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._account_id

    @account_id.setter
    def account_id(self, account_id):
        self._account_id = account_id

    @property
    def budget_name(self):
        """
        The budget name that the campaign associated, only for campaigns that use a shared budget

        Corresponds to 'Budget Name' field in bulk file.
        :rtype: str
        """
        return self._budget_name

    @budget_name.setter
    def budget_name(self, value):
        self._budget_name = value

    @property
    def campaign(self):
        """ Defines a campaign within an account.

        See Campaign at https://docs.microsoft.com/en-us/bingads/campaign-management-service/campaign?view=bingads-13
        """

        return self._campaign

    @campaign.setter
    def campaign(self, campaign):
        self._campaign = campaign

    @property
    def quality_score_data(self):
        """ The quality score data for the campaign.

        :rtype: QualityScoreData
        """

        return self._quality_score_data

    def _get_shopping_setting(self):
        return self._get_setting(_ShoppingSetting, 'ShoppingSetting')

    def _get_target_setting(self):
        return self._get_setting(_ShoppingSetting, 'TargetSetting')

    def _get_dsa_setting(self):
        return self._get_setting(_DsaSetting, 'DynamicSearchAdsSetting')

    def _get_setting(self, setting_type, setting_name):
        if not self.campaign.Settings.Setting:
            return None
        settings = [
            setting for setting in self.campaign.Settings.Setting
            if isinstance(setting, setting_type)
        ]
        if len(settings) != 1:
            raise ValueError('Can only have 1 ' + setting_name +
                             ' in Campaign Settings.')
        return settings[0]

    @staticmethod
    def _write_campaign_type(c):
        if not c.campaign.CampaignType:
            return None
        if len(c.campaign.CampaignType) != 1:
            raise ValueError("Only 1 CampaignType can be set in Campaign")
        return c.campaign.CampaignType[0]

    @staticmethod
    def _read_campaign_type(c, v):
        if not v:
            return []
        campaign_type = v
        c.campaign.CampaignType = [campaign_type]

        if campaign_type.lower() == 'shopping' or campaign_type.lower(
        ) == 'audience':
            BulkCampaign._create_campaign_setting(c.campaign,
                                                  'ShoppingSetting')
        elif campaign_type.lower() == 'dynamicsearchads':
            BulkCampaign._create_campaign_setting(c.campaign,
                                                  'DynamicSearchAdsSetting')

    @staticmethod
    def _create_campaign_setting(campaign, setting_type):
        campaign.Settings = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'ArrayOfSetting')
        setting = _CAMPAIGN_OBJECT_FACTORY_V13.create(setting_type)
        setting.Type = setting_type
        campaign.Settings.Setting = [setting]

    @staticmethod
    def _write_store_id(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            return bulk_str(shopping_setting.StoreId)

    @staticmethod
    def _read_store_id(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            shopping_setting.StoreId = int(v) if v else None

    @staticmethod
    def _write_priority(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            return bulk_str(shopping_setting.Priority)

    @staticmethod
    def _read_priority(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            shopping_setting.Priority = int(v) if v else None

    @staticmethod
    def _write_sales_country_code(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            return shopping_setting.SalesCountryCode

    @staticmethod
    def _read_sales_country_code(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            shopping_setting.SalesCountryCode = v

    @staticmethod
    def _write_local_inventory_ads_enabled(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            return shopping_setting.LocalInventoryAdsEnabled

    @staticmethod
    def _read_local_inventory_ads_enabled(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'shopping' in campgaign_types or 'audience' in campgaign_types:
            shopping_setting = c._get_shopping_setting()
            if not shopping_setting:
                return None
            shopping_setting.LocalInventoryAdsEnabled = v.lower(
            ) == 'true' if v else None

    @staticmethod
    def _read_source(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            dsa_setting.Source = v

    @staticmethod
    def _write_source(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            return bulk_str(dsa_setting.Source)

    @staticmethod
    def _read_domain_language(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            dsa_setting.Language = v

    @staticmethod
    def _write_domain_language(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            return bulk_str(dsa_setting.Language)

    @staticmethod
    def _read_page_feed_ids(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            dsa_setting.PageFeedIds.long = csv_to_field_PageFeedIds(v)

    @staticmethod
    def _write_page_feed_ids(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            return field_to_csv_Ids(dsa_setting.PageFeedIds, c.campaign.Id)

    @staticmethod
    def _read_website(c, v):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            dsa_setting.DomainName = v

    @staticmethod
    def _write_website(c):
        if not c.campaign.CampaignType:
            return None
        campgaign_types = [
            campaign_type.lower() for campaign_type in c.campaign.CampaignType
        ]
        if 'dynamicsearchads' in campgaign_types:
            dsa_setting = c._get_dsa_setting()
            if not dsa_setting:
                return None
            return bulk_str(dsa_setting.DomainName)

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.CampaignType,
            field_to_csv=lambda c: BulkCampaign._write_campaign_type(c),
            csv_to_field=lambda c, v: BulkCampaign._read_campaign_type(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.campaign.Status),
            csv_to_field=lambda c, v: setattr(c.campaign, 'Status', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.campaign.Id),
            csv_to_field=lambda c, v: setattr(c.campaign, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.account_id),
            csv_to_field=lambda c, v: setattr(c, '_account_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign.Name,
            csv_to_field=lambda c, v: setattr(c.campaign, 'Name', v)),
        _SimpleBulkMapping(
            header=_StringTable.TimeZone,
            field_to_csv=lambda c: c.campaign.TimeZone,
            csv_to_field=lambda c, v: setattr(c.campaign, 'TimeZone', v)),
        _SimpleBulkMapping(
            header=_StringTable.Language,
            field_to_csv=lambda c: field_to_csv_CampaignLanguages(c.campaign.
                                                                  Languages),
            csv_to_field=lambda c, v: csv_to_field_CampaignLanguages(
                c.campaign.Languages, v)),
        _ComplexBulkMapping(budget_to_csv, csv_to_budget),
        _SimpleBulkMapping(header=_StringTable.BidAdjustment,
                           field_to_csv=lambda c: bulk_str(
                               c.campaign.AudienceAdsBidAdjustment),
                           csv_to_field=lambda c, v: setattr(
                               c.campaign, 'AudienceAdsBidAdjustment',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.BingMerchantCenterId,
            field_to_csv=lambda c: BulkCampaign._write_store_id(c),
            csv_to_field=lambda c, v: BulkCampaign._read_store_id(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.CampaignPriority,
            field_to_csv=lambda c: BulkCampaign._write_priority(c),
            csv_to_field=lambda c, v: BulkCampaign._read_priority(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.CountryCode,
            field_to_csv=lambda c: BulkCampaign._write_sales_country_code(c),
            csv_to_field=lambda c, v: BulkCampaign._read_sales_country_code(
                c, v)),
        _SimpleBulkMapping(header=_StringTable.LocalInventoryAdsEnabled,
                           field_to_csv=lambda c: BulkCampaign.
                           _write_local_inventory_ads_enabled(c),
                           csv_to_field=lambda c, v: BulkCampaign.
                           _read_local_inventory_ads_enabled(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.campaign.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(
                c.campaign, 'TrackingUrlTemplate', v if v else None)),
        _SimpleBulkMapping(header=_StringTable.CustomParameter,
                           field_to_csv=lambda c:
                           field_to_csv_UrlCustomParameters(c.campaign),
                           csv_to_field=lambda c, v:
                           csv_to_field_UrlCustomParameters(c.campaign, v)),
        _ComplexBulkMapping(biddingscheme_to_csv, csv_to_biddingscheme),
        _SimpleBulkMapping(
            header=_StringTable.BudgetId,
            field_to_csv=lambda c: bulk_str(c.campaign.BudgetId),
            csv_to_field=lambda c, v: setattr(c.campaign, 'BudgetId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.BudgetType,
            field_to_csv=lambda c: bulk_str(c.campaign.BudgetType),
            csv_to_field=lambda c, v: csv_to_field_BudgetType(c.campaign, v)),
        _SimpleBulkMapping(
            header=_StringTable.BudgetName,
            field_to_csv=lambda c: bulk_str(c.budget_name),
            csv_to_field=lambda c, v: setattr(c, 'budget_name', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Website,
            field_to_csv=lambda c: BulkCampaign._write_website(c),
            csv_to_field=lambda c, v: BulkCampaign._read_website(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.DomainLanguage,
            field_to_csv=lambda c: BulkCampaign._write_domain_language(c),
            csv_to_field=lambda c, v: BulkCampaign._read_domain_language(c, v
                                                                         )),
        _SimpleBulkMapping(
            header=_StringTable.Source,
            field_to_csv=lambda c: BulkCampaign._write_source(c),
            csv_to_field=lambda c, v: BulkCampaign._read_source(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.SubType,
            field_to_csv=lambda c: c.campaign.SubType,
            csv_to_field=lambda c, v: setattr(c.campaign, 'SubType', v)),
        _SimpleBulkMapping(
            header=_StringTable.ExperimentId,
            field_to_csv=lambda c: bulk_str(c.campaign.ExperimentId),
            csv_to_field=lambda c, v: setattr(c.campaign, 'ExperimentId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.TargetSetting,
            field_to_csv=lambda c: target_setting_to_csv(c.campaign),
            csv_to_field=lambda c, v: csv_to_target_setting(c.campaign, v)),
        _SimpleBulkMapping(header=_StringTable.FinalUrlSuffix,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.campaign.FinalUrlSuffix, c.campaign.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.campaign, 'FinalUrlSuffix', v)),
        _SimpleBulkMapping(
            header=_StringTable.PageFeedIds,
            field_to_csv=lambda c: BulkCampaign._write_page_feed_ids(c),
            csv_to_field=lambda c, v: BulkCampaign._read_page_feed_ids(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.AdScheduleUseSearcherTimeZone,
            field_to_csv=lambda c: field_to_csv_UseSearcherTimeZone(
                c.campaign.AdScheduleUseSearcherTimeZone, c.campaign.Id),
            csv_to_field=lambda c, v: setattr(
                c.campaign, 'AdScheduleUseSearcherTimeZone', parse_bool(v))),
    ]

    def read_additional_data(self, stream_reader):
        super(BulkCampaign, self).read_additional_data(stream_reader)

    def process_mappings_from_row_values(self, row_values):
        self._campaign = _CAMPAIGN_OBJECT_FACTORY_V13.create('Campaign')
        row_values.convert_to_entity(self, BulkCampaign._MAPPINGS)
        self._quality_score_data = QualityScoreData.read_from_row_values_or_null(
            row_values)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.campaign, 'campaign')
        self.convert_to_values(row_values, BulkCampaign._MAPPINGS)
        if not exclude_readonly_data:
            QualityScoreData.write_to_row_values_if_not_null(
                self.quality_score_data, row_values)