class BulkRemarketingList(BulkAudience):
    """ Represents an Remarketing List that can be read or written in a bulk file.

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

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

    *See also:*

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

    def __init__(self,
                 remarketing_list=None,
                 status=None,):
        super(BulkRemarketingList, self).__init__(audience = remarketing_list, status = status)

    _MAPPINGS = [
       
        _SimpleBulkMapping(
            _StringTable.TagId,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.TagId),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'TagId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            _StringTable.RemarketingRule,
            field_to_csv=lambda c: field_to_csv_RemarketingRule(c.remarketing_list),
            csv_to_field=lambda c, v: csv_to_field_RemarketingRule(c.remarketing_list, v)
        ),
    ]

    @property
    def remarketing_list(self):
        """ Defines a Remarketing List """

        return self._audience

    @remarketing_list.setter
    def remarketing_list(self, remarketing_list):
        self._audience = remarketing_list
   

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.remarketing_list, 'remarketing_list')
        super(BulkRemarketingList, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkRemarketingList._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self.remarketing_list = _CAMPAIGN_OBJECT_FACTORY_V13.create('RemarketingList')
        super(BulkRemarketingList, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkRemarketingList._MAPPINGS)
class BulkKeywordBidSuggestion(_BulkObject):
    """ Represents a best position bid suggestion.

    It can only be read from a bulk file by the :class:`.BulkFileReader` when reading the corresponding :class:`.BulkKeyword`.
    An instance of this class can represent a single keyword bid position, and thus one record in the bulk file.
    """
    def __init__(self):
        self._keyword_text = None
        self._bid = None
        self._performance_data = None

    @property
    def keyword_text(self):
        """ The keyword corresponding to the suggested bid.

        Corresponds to the 'Keyword' field in the bulk file.
        :rtype: str
        """

        return self._keyword_text

    @property
    def bid(self):
        """ The suggested bid for the keyword.

        :rtype: float
        """

        return self._bid

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Keyword,
            field_to_csv=lambda c: bulk_str(c.keyword_text),
            csv_to_field=lambda c, v: setattr(c, '_keyword_text', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Bid,
            field_to_csv=lambda c: bulk_str(c.bid),
            csv_to_field=lambda c, v: setattr(c, '_bid',
                                              float(v) if v else None)),
    ]

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, BulkKeywordBidSuggestion._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, BulkKeywordBidSuggestion._MAPPINGS)

    @staticmethod
    def write_if_not_null(keyword_bid_suggestion, row_writer):
        if keyword_bid_suggestion is not None:
            row_writer.write_object_row(keyword_bid_suggestion)
예제 #3
0
class _BulkAdGroupAdExtensionAssociation(_BulkAdExtensionAssociation):
    """ This abstract class provides properties that are shared by all bulk ad group ad extension association classes. """

    def __init__(self,
                 ad_extension_id_to_entity_id_association=None,
                 status=None,
                 editorial_status=None):
        super(_BulkAdGroupAdExtensionAssociation, self).__init__(
            ad_extension_id_to_entity_id_association,
            status,
            editorial_status,
        )
        self._ad_group_name = None
        self._campaign_name = None

    _MAPPINGS = [
        _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.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, '_campaign_name', v)
        )
    ]

    def process_mappings_from_row_values(self, row_values):
        super(_BulkAdGroupAdExtensionAssociation, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, _BulkAdGroupAdExtensionAssociation._MAPPINGS)

    @property
    def ad_group_name(self):
        """ The name of the ad group that the ad extension is associated.

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

        :rtype str
        """

        return self._ad_group_name

    @property
    def campaign_name(self):
        """ The name of the campaign containing the ad group that the ad extension is associated.

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

        :rtype: str
        """

        return self._campaign_name
class _BulkNegativeSiteIdentifier(_BulkEntityIdentifier):
    def __init__(self, status=None, entity_id=None, entity_name=None):
        self._status = status
        self._entity_id = entity_id
        self._entity_name = entity_name

    @property
    def status(self):
        return self._status

    @property
    def entity_id(self):
        return self._entity_id

    @property
    def entity_name(self):
        return self._entity_name

    @property
    def _parent_column_name(self):
        raise NotImplementedError()

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c._status),
            csv_to_field=lambda c, v: setattr(c, '_status', v if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: None
            if c._entity_id == 0 else bulk_str(c._entity_id),
            csv_to_field=lambda c, v: setattr(c, '_entity_id',
                                              int(v) if v else 0)),
        _DynamicColumnNameMapping(
            header_func=lambda c: c._parent_column_name,
            field_to_csv=lambda c: c._entity_name,
            csv_to_field=lambda c, v: setattr(c, '_entity_name', v))
    ]

    @property
    def is_delete_row(self):
        return self._status == 'Deleted'

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self,
                                     _BulkNegativeSiteIdentifier._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values,
                               _BulkNegativeSiteIdentifier._MAPPINGS)
예제 #5
0
class BulkProductAd(_BulkAd):
    """ Represents a product ad.

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

    For more information, see Product Ad 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,
                 ad=None):
        super(BulkProductAd, self).__init__(ad_group_id, campaign_name,
                                            ad_group_name, ad)
        self.product_ad = ad

    @property
    def product_ad(self):
        """ The product ad.

        See Product Ad at: https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad

    @product_ad.setter
    def product_ad(self, product_ad):
        if product_ad is not None and not isinstance(product_ad, ProductAd):
            raise ValueError('Not an instance of ProductAd')
        self._ad = product_ad

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.PromotionalText,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.product_ad.PromotionalText, c.product_ad.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.product_ad, 'PromotionalText', v
                               if v else '')),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.product_ad = _CAMPAIGN_OBJECT_FACTORY_V13.create('ProductAd')
        self.product_ad.Type = 'Product'
        super(BulkProductAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkProductAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.product_ad, 'product_ad')
        super(BulkProductAd,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkProductAd._MAPPINGS)
class BulkCustomerList(BulkAudience):
    """ Represents a CustomerList that can be read or written in a bulk file.

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

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

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, customer_list=None, status=None, action_type=None):
        super(BulkCustomerList, self).__init__(audience=customer_list,
                                               status=status)
        self._action_type = action_type

    _MAPPINGS = [
        _SimpleBulkMapping(
            _StringTable.ActionType,
            field_to_csv=lambda c: bulk_str(c.action_type),
            csv_to_field=lambda c, v: setattr(c, 'action_type', v))
    ]

    @property
    def action_type(self):
        """ Defines a action_type """

        return self._action_type

    @action_type.setter
    def action_type(self, action_type):
        self._action_type = action_type

    @property
    def customer_list(self):
        """ Defines a CustomerList """

        return self._audience

    @customer_list.setter
    def customer_list(self, customer_list):
        self._audience = customer_list

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.customer_list, 'customer_list')
        super(BulkCustomerList,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCustomerList._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self.customer_list = _CAMPAIGN_OBJECT_FACTORY_V13.create('Audience')
        super(BulkCustomerList,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCustomerList._MAPPINGS)
class BulkCalloutAdExtension(_BulkAdExtensionBase):
    """ Represents a callout ad extension.

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

    For more information, see Callout 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, _CalloutAdExtension):
            raise ValueError(
                'The type of ad_extension is: {0}, should be: {1}'.format(
                    type(ad_extension), 'CalloutAdExtension'))
        super(BulkCalloutAdExtension, self).__init__(account_id=account_id,
                                                     ad_extension=ad_extension)

    @property
    def callout_ad_extension(self):
        """ The callout ad extension.

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

        return self._ad_extension

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

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.CalloutText,
                           field_to_csv=lambda c: c.callout_ad_extension.Text,
                           csv_to_field=lambda c, v: setattr(
                               c.callout_ad_extension, 'Text', v))
    ]

    def process_mappings_from_row_values(self, row_values):
        self.callout_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'CalloutAdExtension')
        self.callout_ad_extension.Type = 'CalloutAdExtension'
        super(BulkCalloutAdExtension,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCalloutAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.callout_ad_extension,
                                         'callout_ad_extension')
        super(BulkCalloutAdExtension,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCalloutAdExtension._MAPPINGS)
예제 #8
0
class BulkCombinedList(BulkAudience):
    """ Represents a CombinedList that can be read or written in a bulk file.

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

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

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, combined_list=None, status=None):
        super(BulkCombinedList, self).__init__(audience=combined_list,
                                               status=status)

    _MAPPINGS = [
        _SimpleBulkMapping(
            _StringTable.CombinationRule,
            field_to_csv=lambda c: combination_rules_to_bulkstring(
                c.combined_list.CombinationRules)
            if c.combined_list.CombinationRules else None,
            csv_to_field=lambda c, v: parse_combination_rules(
                c.combined_list, v))
    ]

    @property
    def combined_list(self):
        """ Defines a CombinedList """

        return self._audience

    @combined_list.setter
    def combined_list(self, combined_list):
        self._audience = combined_list

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.combined_list, 'combined_list')
        super(BulkCombinedList,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCombinedList._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self.combined_list = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'CombinedList')
        super(BulkCombinedList,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCombinedList._MAPPINGS)
예제 #9
0
class BulkCampaignLabel(_BulkLabelAssociation):
    """ Represents a campaign label.

    Defines an association record between a Campaign and a Label that can be uploaded and downloaded in a bulk file.

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

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, label_association=None, status=None, campaign=None):
        super(BulkCampaignLabel, self).__init__(label_association, status)
        self._campaign = campaign

    @property
    def campaign(self):
        """ The campaign name of the Campaign Management Service.

        A subset of Label properties are available in the Ad Group record.
        """

        return self._campaign

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

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Campaign,
                           field_to_csv=lambda c: c.campaign,
                           csv_to_field=lambda c, v: setattr(c, 'campaign', v))
    ]

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        super(BulkCampaignLabel,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCampaignLabel._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        super(BulkCampaignLabel,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCampaignLabel._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignLabel, self).read_additional_data(stream_reader)
class BulkPromotionAdExtension(_BulkAdExtensionBase):
    """ Represents a promotion ad extension.

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

    For more information, see Promotion 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, _PromotionAdExtension):
            raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format(
                type(ad_extension),
                'PromotionAdExtension'
            ))
        super(BulkPromotionAdExtension, self).__init__(
            account_id=account_id,
            ad_extension=ad_extension
        )
        

    @property
    def promotion_ad_extension(self):
        """ The promotion ad extension.

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

        return self._ad_extension

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

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Language,
            field_to_csv=lambda c: bulk_str(c.promotion_ad_extension.Language),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'Language', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CurrencyCode,
            field_to_csv=lambda c: bulk_str(c.promotion_ad_extension.CurrencyCode),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'CurrencyCode', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.PromotionCode,
            field_to_csv=lambda c: bulk_optional_str(c.promotion_ad_extension.PromotionCode, c.promotion_ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'PromotionCode', v if v else '')
        ),
        _SimpleBulkMapping(
            header=_StringTable.PromotionTarget,
            field_to_csv=lambda c: bulk_str(c.promotion_ad_extension.PromotionItem),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'PromotionItem', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.PromotionStart,
            field_to_csv=lambda c: field_to_csv_SchedulingDate(c.promotion_ad_extension.PromotionStartDate, c.promotion_ad_extension.Id) if c._ad_extension.Scheduling else None,
            csv_to_field=lambda c, v: csv_to_field_Date(c.promotion_ad_extension, 'PromotionStartDate', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.PromotionEnd,
            field_to_csv=lambda c: field_to_csv_SchedulingDate(c.promotion_ad_extension.PromotionEndDate, c.promotion_ad_extension.Id) if c._ad_extension.Scheduling else None,
            csv_to_field = lambda c, v: csv_to_field_Date(c.promotion_ad_extension, 'PromotionEndDate', v)
        ),        
        _SimpleBulkMapping(
            header=_StringTable.MoneyAmountOff,
            field_to_csv=lambda c: c.promotion_ad_extension.MoneyAmountOff,
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'MoneyAmountOff',float(v) if v else None)
        ),        
        _SimpleBulkMapping(
            header=_StringTable.OrdersOverAmount,
            field_to_csv=lambda c: c.promotion_ad_extension.OrdersOverAmount,
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'OrdersOverAmount',float(v) if v else None)
        ),        
        _SimpleBulkMapping(
            header=_StringTable.PercentOff,
            field_to_csv=lambda c: c.promotion_ad_extension.PercentOff,
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'PercentOff',float(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.DiscountModifier,
            field_to_csv=lambda c: bulk_str(c.promotion_ad_extension.DiscountModifier),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'DiscountModifier', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Occasion,
            field_to_csv=lambda c: bulk_str(c.promotion_ad_extension.PromotionOccasion),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'PromotionOccasion', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.promotion_ad_extension.FinalUrls, c.promotion_ad_extension.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.promotion_ad_extension.FinalUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.promotion_ad_extension.FinalMobileUrls, c.promotion_ad_extension.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.promotion_ad_extension.FinalMobileUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_optional_str(c.promotion_ad_extension.TrackingUrlTemplate, c.promotion_ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'TrackingUrlTemplate', v if v else '')
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.promotion_ad_extension),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.promotion_ad_extension, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(c.promotion_ad_extension.FinalUrlSuffix, c.promotion_ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c.promotion_ad_extension, 'FinalUrlSuffix', v)
        )
    ]

    def process_mappings_from_row_values(self, row_values):
        self.promotion_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V13.create('PromotionAdExtension')
        self.promotion_ad_extension.Type = 'PromotionAdExtension'
        super(BulkPromotionAdExtension, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkPromotionAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.promotion_ad_extension, 'promotion_ad_extension')
        super(BulkPromotionAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkPromotionAdExtension._MAPPINGS)
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)
class BulkLocationAdExtension(_BulkAdExtensionBase):
    """ Represents an location ad extension.

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

    For more information, see Location 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, _LocationAdExtension):
            raise ValueError(
                'The type of ad_extension is: {0}, should be: {1}'.format(
                    type(ad_extension), 'LocationAdExtension'))
        super(BulkLocationAdExtension,
              self).__init__(account_id=account_id, ad_extension=ad_extension)

    @property
    def location_ad_extension(self):
        """ The location ad extension.

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

        return self._ad_extension

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

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.BusinessName,
            field_to_csv=lambda c: c.location_ad_extension.CompanyName,
            csv_to_field=lambda c, v: setattr(c.location_ad_extension,
                                              'CompanyName', v)),
        _SimpleBulkMapping(header=_StringTable.PhoneNumber,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.location_ad_extension.PhoneNumber, c.
                               location_ad_extension.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.location_ad_extension, 'PhoneNumber', v
                               if v else '')),
        _SimpleBulkMapping(header=_StringTable.GeoCodeStatus,
                           field_to_csv=lambda c: bulk_str(
                               c.location_ad_extension.GeoCodeStatus),
                           csv_to_field=lambda c, v: setattr(
                               c.location_ad_extension, 'GeoCodeStatus', v
                               if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.AddressLine1,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.StreetAddress),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'StreetAddress', v))),
        _SimpleBulkMapping(
            header=_StringTable.AddressLine2,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: bulk_optional_str(x.StreetAddress2, c.
                                               location_ad_extension.Id)),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'StreetAddress2', v if v else ''))),
        _SimpleBulkMapping(
            header=_StringTable.City,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.CityName),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'CityName', v))),
        _SimpleBulkMapping(
            header=_StringTable.ProvinceName,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.ProvinceName),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'ProvinceName', v))),
        _SimpleBulkMapping(
            header=_StringTable.StateOrProvince,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.ProvinceCode),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'ProvinceCode', v))),
        _SimpleBulkMapping(
            header=_StringTable.PostalCode,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.PostalCode),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'PostalCode', v))),
        _SimpleBulkMapping(
            header=_StringTable.CountryCode,
            field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(
                c, lambda x: x.CountryCode),
            csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part(
                c, lambda x: setattr(x, 'CountryCode', v))),
        _SimpleBulkMapping(
            header=_StringTable.Latitude,
            field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part(
                c, lambda x: bulk_str(
                    float(x.LatitudeInMicroDegrees) / 1000000.0)
                if x.LatitudeInMicroDegrees is not None else None),
            csv_to_field=lambda c, v: BulkLocationAdExtension.
            set_geo_point_part(
                c, lambda x, latitude: setattr(
                    x, 'LatitudeInMicroDegrees',
                    int(round(float(latitude) * 1000000))), v)),
        _SimpleBulkMapping(
            header=_StringTable.Longitude,
            field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part(
                c, lambda x: bulk_str(
                    float(x.LongitudeInMicroDegrees) / 1000000.0)
                if x.LongitudeInMicroDegrees is not None else None),
            csv_to_field=lambda c, v: BulkLocationAdExtension.
            set_geo_point_part(
                c, lambda x, longitude: setattr(
                    x, 'LongitudeInMicroDegrees',
                    int(round(float(longitude) * 1000000))), v)),
    ]

    @staticmethod
    def get_address_part(bulk_ad_extension, get_func):
        if bulk_ad_extension.location_ad_extension.Address is not None:
            return get_func(bulk_ad_extension.location_ad_extension.Address)
        else:
            return None

    @staticmethod
    def set_address_part(bulk_ad_extension, set_func):
        if bulk_ad_extension.location_ad_extension.Address is None:
            bulk_ad_extension.location_ad_extension.Address = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'Address')
        set_func(bulk_ad_extension.location_ad_extension.Address)

    @staticmethod
    def get_geo_point_part(bulk_ad_extension, get_func):
        if bulk_ad_extension.location_ad_extension.GeoPoint is not None:
            return get_func(bulk_ad_extension.location_ad_extension.GeoPoint)
        else:
            return None

    @staticmethod
    def set_geo_point_part(bulk_ad_extension, set_func, value):
        if not value:
            return
        if bulk_ad_extension.location_ad_extension.GeoPoint is None:
            bulk_ad_extension.location_ad_extension.GeoPoint = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'GeoPoint')
        set_func(bulk_ad_extension.location_ad_extension.GeoPoint, value)

    def process_mappings_from_row_values(self, row_values):
        self.location_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'LocationAdExtension')
        self.location_ad_extension.Type = 'LocationAdExtension'
        if row_values[_StringTable.Latitude] or row_values[
                _StringTable.Longitude]:
            self.location_ad_extension.GeoPoint = _CAMPAIGN_OBJECT_FACTORY_V13.create(
                'GeoPoint')
        super(BulkLocationAdExtension,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkLocationAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.location_ad_extension,
                                         'location_ad_extension')
        super(BulkLocationAdExtension,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkLocationAdExtension._MAPPINGS)
class BulkCampaignNegativeStoreCriterion(_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 Store Criterion record in a bulk file.

    For more information, see Campaign Negative Store Criterion 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(BulkCampaignNegativeStoreCriterion, 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.BingMerchantCenterId,
            field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.
                                            Criterion.StoreId),
            csv_to_field=lambda c, v: setattr(
                c.negative_campaign_criterion.Criterion, 'StoreId',
                int(v) if v 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

    @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(
            'StoreCriterion')
        self._negative_campaign_criterion.Criterion.Type = 'StoreCriterion'

        row_values.convert_to_entity(
            self, BulkCampaignNegativeStoreCriterion._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,
                               BulkCampaignNegativeStoreCriterion._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignNegativeStoreCriterion,
              self).read_additional_data(stream_reader)
예제 #14
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 BulkExperiment(_SingleRecordBulkEntity):
    """ Represents an experiment.

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

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

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, experiment=None):
        super(BulkExperiment, self).__init__()
        self._experiment = experiment

    @property
    def experiment(self):
        """ The experiment.
        """
        return self._experiment

    @experiment.setter
    def experiment(self, experiment):
        self._experiment = experiment

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.experiment.Id),
            csv_to_field=lambda c, v: setattr(c.experiment, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: c.experiment.ExperimentStatus,
            csv_to_field=lambda c, v: setattr(c.experiment, 'ExperimentStatus',
                                              v)),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: c.experiment.Name,
            csv_to_field=lambda c, v: setattr(c.experiment, 'Name', v)),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: bulk_date_str(c.experiment.StartDate),
            csv_to_field=lambda c, v: setattr(c.experiment, 'StartDate',
                                              parse_date(v))),
        _SimpleBulkMapping(header=_StringTable.EndDate,
                           field_to_csv=lambda c: field_to_csv_SchedulingDate(
                               c.experiment.EndDate, c.experiment.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.experiment, 'EndDate', parse_date(v))),
        _SimpleBulkMapping(
            header=_StringTable.TrafficSplitPercent,
            field_to_csv=lambda c: bulk_str(c.experiment.TrafficSplitPercent),
            csv_to_field=lambda c, v: setattr(c.experiment,
                                              'TrafficSplitPercent',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.BaseCampaignId,
            field_to_csv=lambda c: bulk_str(c.experiment.BaseCampaignId),
            csv_to_field=lambda c, v: setattr(c.experiment, 'BaseCampaignId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ExperimentCampaignId,
            field_to_csv=lambda c: bulk_str(c.experiment.ExperimentCampaignId),
            csv_to_field=lambda c, v: setattr(c.experiment,
                                              'ExperimentCampaignId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.ExperimentType,
                           field_to_csv=lambda c: c.experiment.ExperimentType,
                           csv_to_field=lambda c, v: setattr(
                               c.experiment, 'ExperimentType', v)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.experiment = _CAMPAIGN_OBJECT_FACTORY_V13.create('Experiment')
        row_values.convert_to_entity(self, BulkExperiment._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self._experiment, 'Experiment')
        self.convert_to_values(row_values, BulkExperiment._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkExperiment, self).read_additional_data(stream_reader)
예제 #16
0
class BulkCampaignAgeCriterion(_SingleRecordBulkEntity):
    """ Represents an Campaign Age Criterion that can be read or written in a bulk file.

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

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

    *See also:*

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

        self._biddable_campaign_criterion = biddable_campaign_criterion
        self._campaign_name = campaign_name

    _MAPPINGS = [
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.Status),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'Status', v
                               if v else None)),
        _SimpleBulkMapping(
            _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(_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(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.BidAdjustment,
            field_to_csv=lambda c: field_to_csv_BidAdjustment(
                c.biddable_campaign_criterion),
            csv_to_field=lambda c, v: csv_to_field_BidAdjustment(
                c.biddable_campaign_criterion,
                float(v) if v else None)),
        _SimpleBulkMapping(_StringTable.Target,
                           field_to_csv=lambda c: field_to_csv_AgeTarget(
                               c.biddable_campaign_criterion),
                           csv_to_field=lambda c, v: csv_to_field_AgeTarget(
                               c.biddable_campaign_criterion, v)),
    ]

    @property
    def biddable_campaign_criterion(self):
        """ Defines a 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

    @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

    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, BulkCampaignAgeCriterion._MAPPINGS)

    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(
            'AgeCriterion')
        self._biddable_campaign_criterion.Criterion.Type = 'AgeCriterion'
        self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'BidMultiplier')
        self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier'
        row_values.convert_to_entity(self, BulkCampaignAgeCriterion._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignAgeCriterion,
              self).read_additional_data(stream_reader)
예제 #17
0
class BulkAccount(_SingleRecordBulkEntity):
    """ Represents an account that can be read or written in a bulk file.

    Properties of this class and of classes that it is derived from, correspond to fields of the Account record in a bulk file.
    For more information, see Account at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, customer_id=None, sync_time=None):
        super(BulkAccount, self).__init__()
        self._id = account_id
        self._customer_id = customer_id
        self._sync_time = sync_time
        self._msclkid_auto_tagging_enabled = None
        self._tracking_url_template = None
        self._final_url_suffix = None

    @property
    def id(self):
        """ The identifier of the account.

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

        :return: The identifier of the account.
        :rtype: int
        """

        return self._id

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

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

        :return: The identifier of the customer that contains the account.
        :rtype: int
        """

        return self._customer_id

    @property
    def sync_time(self):
        """ The date and time that you last synced your account using the bulk service.

        You should keep track of this value in UTC time.
        Corresponds to the 'Sync Time' field in the bulk file.

        :return: The date and time that you last synced your account using the bulk service.
        :rtype: datetime.datetime
        """

        return self._sync_time

    @property
    def msclkid_auto_tagging_enabled(self):
        """ Determines whether auto-tagging of the MSCLKID query string parameter is enabled. The MSCLKID is a 32-character GUID that is unique for each ad click.
        :return: The msclkid autotag setting of the account
        :rtype: bool
        """
        return self._msclkid_auto_tagging_enabled

    @property
    def tracking_url_template(self):
        """ The tracking template to use as a default for all URLs in your account.
        
        :return: The tracking template of the account
        :rtype: str
        """
        return self._tracking_url_template

    @property
    def final_url_suffix(self):
        """ The final url suffix to use as a default for all URLs in your account.
        
        :return: The tracking template of the account
        :rtype: str
        """
        return self._final_url_suffix

    @final_url_suffix.setter
    def final_url_suffix(self, v):
        self._final_url_suffix = v

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.id),
            csv_to_field=lambda c, v: setattr(c, '_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.customer_id),
            csv_to_field=lambda c, v: setattr(c, '_customer_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.SyncTime,
            field_to_csv=lambda c: bulk_datetime_str(c.sync_time),
            csv_to_field=lambda c, v: setattr(c, '_sync_time',
                                              parse_datetime(v)
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.MSCLKIDAutoTaggingEnabled,
            field_to_csv=lambda c: bulk_str(c.msclkid_auto_tagging_enabled),
            csv_to_field=lambda c, v: setattr(
                c, '_msclkid_auto_tagging_enabled', parse_bool(v))),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.tracking_url_template),
            csv_to_field=lambda c, v: setattr(c, '_tracking_url_template', v)),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(c.final_url_suffix, c.id),
            csv_to_field=lambda c, v: setattr(c, '_final_url_suffix', v)),
    ]

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

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self.convert_to_values(row_values, BulkAccount._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAccount, self).read_additional_data(stream_reader)
class _BulkAdGroupNegativeSitesIdentifier(_BulkNegativeSiteIdentifier):
    def __init__(self,
                 status=None,
                 ad_group_id=None,
                 ad_group_name=None,
                 campaign_name=None):
        super(_BulkAdGroupNegativeSitesIdentifier, self).__init__(
            status,
            ad_group_id,
            ad_group_name,
        )
        self._campaign_name = campaign_name

    def __eq__(self, other):
        is_name_not_empty = (self.campaign_name is not None
                             and len(self.campaign_name) > 0
                             and self.ad_group_name is not None
                             and len(self.ad_group_name) > 0)
        return (
            type(self) == type(other) and
            (self.ad_group_id == other.ad_group_id or
             (is_name_not_empty and self.campaign_name == other.campaign_name
              and self.ad_group_name == other.ad_group_name)))

    @property
    def ad_group_id(self):
        return self._entity_id

    @ad_group_id.setter
    def ad_group_id(self, value):
        self._entity_id = value

    @property
    def ad_group_name(self):
        return self._entity_name

    @ad_group_name.setter
    def ad_group_name(self, value):
        self._entity_name = value

    @property
    def campaign_name(self):
        return self._campaign_name

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

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
    ]

    def read_from_row_values(self, row_values):
        super(_BulkAdGroupNegativeSitesIdentifier,
              self).read_from_row_values(row_values)
        row_values.convert_to_entity(
            self, _BulkAdGroupNegativeSitesIdentifier._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        super(_BulkAdGroupNegativeSitesIdentifier,
              self).write_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values,
                               _BulkAdGroupNegativeSitesIdentifier._MAPPINGS)

    def _create_entity_with_this_identifier(self):
        return BulkAdGroupNegativeSites(identifier=self)

    @property
    def _parent_column_name(self):
        return _StringTable.AdGroup
예제 #19
0
class _BulkAdExtensionBase(_SingleRecordBulkEntity):
    """ This class provides properties that are shared by all bulk ad extension classes.

    *See also:*

    * :class:`.BulkCallAdExtension`
    * :class:`.BulkImageAdExtension`
    * :class:`.BulkLocationAdExtension`
    * :class:`.BulkSiteLinkAdExtension`
    """

    def __init__(self, account_id=None, ad_extension=None):
        super(_BulkAdExtensionBase, self).__init__()

        self._account_id = account_id
        self._ad_extension = ad_extension

    @property
    def account_id(self):
        """ The ad extension's parent account identifier.

        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

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Status),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Version,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Version),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Version', 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.StartDate,
            field_to_csv=lambda c: field_to_csv_SchedulingDate(c._ad_extension.Scheduling.StartDate, c._ad_extension.Id) if c._ad_extension.Scheduling else None,
            csv_to_field=lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'StartDate', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: field_to_csv_SchedulingDate(c._ad_extension.Scheduling.EndDate, c._ad_extension.Id) if c._ad_extension.Scheduling else None,
            csv_to_field = lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'EndDate', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdSchedule,
            field_to_csv=lambda c: field_to_csv_AdSchedule(c._ad_extension.Scheduling, c._ad_extension.Id),
            csv_to_field=lambda c, v: csv_to_field_AdSchedule(c._ad_extension.Scheduling, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.UseSearcherTimeZone,
            field_to_csv=lambda c: field_to_csv_UseSearcherTimeZone(c._ad_extension.Scheduling.UseSearcherTimeZone, c._ad_extension.Id) if c._ad_extension.Scheduling else None,
            csv_to_field=lambda c, v: setattr(c._ad_extension.Scheduling, 'UseSearcherTimeZone', parse_bool(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.DevicePreference,
            field_to_csv=lambda c: bulk_device_preference_str(c._ad_extension.DevicePreference),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'DevicePreference', parse_device_preference(v))
        ),
    ]

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

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkAdExtensionBase._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(_BulkAdExtensionBase, self).read_additional_data(stream_reader)
예제 #20
0
class _BulkAdExtensionIdentifier(_BulkEntityIdentifier):
    def __init__(self,
                 account_id=None,
                 ad_extension_id=None,
                 status=None,
                 version=None):
        super(_BulkAdExtensionIdentifier, self).__init__()

        self._account_id = account_id
        self._ad_extension_id = ad_extension_id
        self._status = status
        self._version = version

    @property
    def account_id(self):
        return self._account_id

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

    @property
    def ad_extension_id(self):
        return self._ad_extension_id

    @ad_extension_id.setter
    def ad_extension_id(self, ad_extension_id):
        self._ad_extension_id = ad_extension_id

    @property
    def status(self):
        return self._status

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

    @property
    def version(self):
        return self._version

    @version.setter
    def version(self, version):
        self._version = version

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.status),
            csv_to_field=lambda c, v: setattr(c, 'status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id),
            csv_to_field=lambda c, v: setattr(c, 'ad_extension_id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Version,
            field_to_csv=lambda c: bulk_str(c.version),
            csv_to_field=lambda c, v: setattr(c, 'version', 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)
        ),
    ]

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, _BulkAdExtensionIdentifier._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkAdExtensionIdentifier._MAPPINGS)

    def __eq__(self, other):
        raise NotImplementedError()

    @property
    def is_delete_row(self):
        return self._status == 'Deleted'
class _BulkNegativeSite(_SingleRecordBulkEntity):
    """ This abstract base class for the bulk negative sites that are assigned individually to a campaign or ad group entity.

    *See also:*

    * :class:`.BulkAdGroupNegativeSite`
    * :class:`.BulkCampaignNegativeSite`
    """
    def __init__(self, identifier, website=None):
        super(_BulkNegativeSite, self).__init__()

        self._identifier = identifier
        self._website = website

    @property
    def website(self):
        """ The URL of a website on which you do not want your ads displayed.

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

        :rtype: str
        """

        return self._website

    @website.setter
    def website(self, website):
        self._website = website

    @property
    def status(self):
        """ The status of the negative site association.

        :rtype: str
        """

        return self._identifier.status

    @status.setter
    def status(self, value):
        self._identifier.status = value

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Website,
                           field_to_csv=lambda c: c.website,
                           csv_to_field=lambda c, v: setattr(c, 'website', v)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self._identifier.read_from_row_values(row_values)
        row_values.convert_to_entity(self, _BulkNegativeSite._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._identifier.write_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, _BulkNegativeSite._MAPPINGS)

    @property
    def can_enclose_in_multiline_entity(self):
        return True

    def enclose_in_multiline_entity(self):
        return self.create_negative_sites_with_this_negative_site()

    def create_negative_sites_with_this_negative_site(self):
        raise NotImplementedError()

    def read_additional_data(self, stream_reader):
        super(_BulkNegativeSite, self).read_additional_data(stream_reader)
예제 #22
0
class BulkResponsiveSearchAd(_BulkAd):
    """ Represents a Responsive Search Ad.

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

    For more information, see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkResponsiveSearchAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self._ad = ad

    @property
    def responsive_search_ad(self):
        """ The responsive search ad.

        see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.
        """

        return self._ad

    @responsive_search_ad.setter
    def responsive_search_ad(self, rsa):
        if rsa is not None and not isinstance(rsa, ResponsiveSearchAd):
            raise ValueError('Not an instance of ResponsiveSearchAd')
        self._ad = rsa

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Path1,
            field_to_csv=lambda c: bulk_optional_str(
                c.responsive_search_ad.Path1, c.responsive_search_ad.Id),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path1',
                                              v)),
        _SimpleBulkMapping(
            header=_StringTable.Path2,
            field_to_csv=lambda c: bulk_optional_str(
                c.responsive_search_ad.Path2, c.responsive_search_ad.Id),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path2',
                                              v)),
        _SimpleBulkMapping(
            header=_StringTable.Domain,
            field_to_csv=lambda c: bulk_optional_str(
                c.responsive_search_ad.Domain, c.responsive_search_ad.Id),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Domain',
                                              v)),
        _SimpleBulkMapping(
            header=_StringTable.Headline,
            field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(
                c.responsive_search_ad.Headlines),
            csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(
                c.responsive_search_ad.Headlines, v)),
        _SimpleBulkMapping(
            header=_StringTable.Description,
            field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(
                c.responsive_search_ad.Descriptions),
            csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(
                c.responsive_search_ad.Descriptions, v))
    ]

    def process_mappings_from_row_values(self, row_values):
        self.responsive_search_ad = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'ResponsiveSearchAd')
        self.responsive_search_ad.Type = 'ResponsiveSearch'
        super(BulkResponsiveSearchAd,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkResponsiveSearchAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.responsive_search_ad,
                                         'responsive_search_ad')
        super(BulkResponsiveSearchAd,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkResponsiveSearchAd._MAPPINGS)
예제 #23
0
class _BulkAdExtensionAssociation(_SingleRecordBulkEntity):
    """ This class provides properties that are shared by all bulk ad extension association classes.

    For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127.
    """

    def __init__(self,
                 ad_extension_id_to_entity_id_association=None,
                 status=None,
                 editorial_status=None):
        super(_BulkAdExtensionAssociation, self).__init__()

        self._status = status
        self._ad_extension_id_to_entity_id_association = ad_extension_id_to_entity_id_association
        self._editorial_status = editorial_status
        self._performance_data = None

    @property
    def ad_extension_id_to_entity_id_association(self):
        """ Defines an association relationship between an ad extension and a supported entity, for example a campaign or ad group.

        :rtype: AdExtensionIdToEntityIdAssociation
        """

        return self._ad_extension_id_to_entity_id_association

    @ad_extension_id_to_entity_id_association.setter
    def ad_extension_id_to_entity_id_association(self, value):
        self._ad_extension_id_to_entity_id_association = value

    @property
    def status(self):
        """ The status of the ad extension association.

        The value is Active if the EntityId and AdExtensionId are associated. The value is Deleted if the association is removed.
        Corresponds to the 'Status' field in the bulk file.

        :rtype: str
        """

        return self._status

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

    @property
    def editorial_status(self):
        """ The editorial status of the ad extension and associated entity.

        For more information, see AdExtensionEditorialStatus at https://go.microsoft.com/fwlink/?linkid=846127.
        Corresponds to the 'Editorial Status' field in the bulk file.

        :rtype: str
        """

        return self._editorial_status

    @editorial_status.setter
    def editorial_status(self, editorial_status):
        self._editorial_status = editorial_status

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.AdExtensionId),
            csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'AdExtensionId', int(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.status),
            csv_to_field=lambda c, v: setattr(c, '_status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.EntityId),
            csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'EntityId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EditorialStatus,
            field_to_csv=lambda c: c.editorial_status,
            csv_to_field=lambda c, v: setattr(c, '_editorial_status', v if v else None)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self._ad_extension_id_to_entity_id_association = _CAMPAIGN_OBJECT_FACTORY_V13.create('AdExtensionIdToEntityIdAssociation')
        row_values.convert_to_entity(self, _BulkAdExtensionAssociation._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(
            self._ad_extension_id_to_entity_id_association,
            'ad_extension_id_to_entity_id_association'
        )
        self.convert_to_values(row_values, _BulkAdExtensionAssociation._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(_BulkAdExtensionAssociation, self).read_additional_data(stream_reader)
예제 #24
0
class BulkFeedItem(_SingleRecordBulkEntity):
    """ Represents a feed item.

    Properties of this class and of classes that it is derived from, correspond to fields of the Feed Item record in a bulk file.
    For more information, see Feed at https://go.microsoft.com/fwlink/?linkid=846127
    
    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    @staticmethod
    def _bulk_datetime_optional_str(value, id):
        if value is None:
            return None

        if not value:
            return "delete_value" if id > 0 else None

        return value.strftime('%Y/%m/%d %H:%M:%S')

    @staticmethod
    def _parse_datetime(value):

        if not value:
            return None
        try:
            if value == 'delete_value':
                return None
            else:
                return datetime.strptime(value, '%Y/%m/%d %H:%M:%S')
        except Exception:
            return parse_datetime(value)

    def __init__(self):
        super(BulkFeedItem, self).__init__()
        self._id = None
        self._feed_id = None
        self._campaign = None
        self._ad_group = None
        self._audience_id = None
        self._custom_attributes = None
        self._status = None
        self._start_date = None
        self._end_date = None
        self._keyword = None
        self._daytime_ranges = None
        self._match_type = None
        self._location_id = None
        self._intent_option = None
        self._device_preference = None
        self._adgroup_id = None
        self._campaign_id = None

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.id),
            csv_to_field=lambda c, v: setattr(c, 'id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.feed_id),
            csv_to_field=lambda c, v: setattr(c, 'feed_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.AudienceId,
            field_to_csv=lambda c: bulk_str(c.audience_id),
            csv_to_field=lambda c, v: setattr(c, 'audience_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Target,
            field_to_csv=lambda c: bulk_str(c.location_id),
            csv_to_field=lambda c, v: setattr(c, 'location_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            header=_StringTable.MatchType,
            field_to_csv=lambda c: c.match_type,
            csv_to_field=lambda c, v: setattr(c, 'match_type', v)),
        _SimpleBulkMapping(
            header=_StringTable.PhysicalIntent,
            field_to_csv=lambda c: c.intent_option,
            csv_to_field=lambda c, v: setattr(c, 'intent_option', v)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: bulk_str(c.campaign),
            csv_to_field=lambda c, v: setattr(c, 'campaign', v)),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: bulk_str(c.ad_group),
            csv_to_field=lambda c, v: setattr(c, 'ad_group', v)),
        _SimpleBulkMapping(header=_StringTable.Keyword,
                           field_to_csv=lambda c: bulk_str(c.keyword),
                           csv_to_field=lambda c, v: setattr(c, 'keyword', v)),
        _SimpleBulkMapping(
            header=_StringTable.CustomAttributes,
            field_to_csv=lambda c: bulk_str(c.custom_attributes),
            csv_to_field=lambda c, v: setattr(c, 'custom_attributes', v)),
        _SimpleBulkMapping(
            header=_StringTable.DevicePreference,
            field_to_csv=lambda c: bulk_device_preference_str(
                c.device_preference),
            csv_to_field=lambda c, v: setattr(c, 'device_preference',
                                              parse_device_preference(v))),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: BulkFeedItem._bulk_datetime_optional_str(
                c.start_date, c.id),
            csv_to_field=lambda c, v: setattr(
                c, 'start_date', BulkFeedItem._parse_datetime(v))),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: BulkFeedItem._bulk_datetime_optional_str(
                c.end_date, c.id),
            csv_to_field=lambda c, v: setattr(
                c, 'end_date', BulkFeedItem._parse_datetime(v))),
        _SimpleBulkMapping(
            header=_StringTable.AdSchedule,
            field_to_csv=lambda c: field_to_csv_FeedItemAdSchedule(c, c.id),
            csv_to_field=lambda c, v: csv_to_field_FeedItemAdSchedule(c, v)),
        _SimpleBulkMapping(
            header=_StringTable.TargetAdGroupId,
            field_to_csv=lambda c: bulk_optional_str(c.adgroup_id, c.id),
            csv_to_field=lambda c, v: setattr(c, 'adgroup_id',
                                              int(v) if v else '')),
        _SimpleBulkMapping(
            header=_StringTable.TargetCampaignId,
            field_to_csv=lambda c: bulk_optional_str(c.campaign_id, c.id),
            csv_to_field=lambda c, v: setattr(c, 'campaign_id',
                                              int(v) if v else '')),
    ]

    @property
    def device_preference(self):
        """ the id of the account which contains the feed
        Corresponds to the 'Device Preference' field in the bulk file.

        :rtype: long
        """
        return self._device_preference

    @device_preference.setter
    def device_preference(self, value):
        self._device_preference = value

    @property
    def intent_option(self):
        """ the id of the account which contains the feed
        Corresponds to the 'Physical Intent' field in the bulk file.

        :rtype: str
        """
        return self._intent_option

    @intent_option.setter
    def intent_option(self, value):
        self._intent_option = value

    @property
    def location_id(self):
        """ the id of the account which contains the feed
        Corresponds to the 'Target' field in the bulk file.

        :rtype: long
        """
        return self._location_id

    @location_id.setter
    def location_id(self, value):
        self._location_id = value

    @property
    def adgroup_id(self):
        """ the id of the account which contains the feed
        Corresponds to the 'Target Ad Group Id' field in the bulk file.

        :rtype: long
        """
        return self._adgroup_id

    @adgroup_id.setter
    def adgroup_id(self, value):
        self._adgroup_id = value

    @property
    def campaign_id(self):
        """ the id of the account which contains the feed
        Corresponds to the 'Target Campaign Id' field in the bulk file.

        :rtype: long
        """
        return self._campaign_id

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

    @property
    def match_type(self):
        """ the match type of bulk record
        Corresponds to the 'Match Type' field in the bulk file.

        :rtype: str
        """
        return self._match_type

    @match_type.setter
    def match_type(self, value):
        self._match_type = value

    @property
    def keyword(self):
        """ the status of bulk record
        Corresponds to the 'Keyword' field in the bulk file.

        :rtype: str
        """
        return self._keyword

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

    @property
    def daytime_ranges(self):
        """ the status of bulk record
        Corresponds to the 'Ad Schedule' field in the bulk file.

        :rtype: str
        """
        return self._daytime_ranges

    @daytime_ranges.setter
    def daytime_ranges(self, value):
        self._daytime_ranges = value

    @property
    def end_date(self):
        """ the status of bulk record
        Corresponds to the 'End Date' field in the bulk file.

        :rtype: str
        """
        return self._end_date

    @end_date.setter
    def end_date(self, value):
        self._end_date = value

    @property
    def start_date(self):
        """ the status of bulk record
        Corresponds to the 'Start Date' field in the bulk file.

        :rtype: str
        """
        return self._start_date

    @start_date.setter
    def start_date(self, value):
        self._start_date = value

    @property
    def custom_attributes(self):
        """ the status of bulk record
        Corresponds to the 'Custom Attributes' field in the bulk file.

        :rtype: str
        """
        return self._custom_attributes

    @custom_attributes.setter
    def custom_attributes(self, value):
        self._custom_attributes = value

    @property
    def audience_id(self):
        """ the status of bulk record
        Corresponds to the 'Audience Id' field in the bulk file.

        :rtype: long
        """
        return self._audience_id

    @audience_id.setter
    def audience_id(self, value):
        self._audience_id = value

    @property
    def ad_group(self):
        """ the status of bulk record
        Corresponds to the 'Ad Group' field in the bulk file.

        :rtype: str
        """
        return self._ad_group

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

    @property
    def id(self):
        """ the status of bulk record
        Corresponds to the 'Id' field in the bulk file.

        :rtype: long
        """
        return self._id

    @id.setter
    def id(self, value):
        self._id = value

    @property
    def feed_id(self):
        """ the status of bulk record
        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: long
        """
        return self._feed_id

    @feed_id.setter
    def feed_id(self, value):
        self._feed_id = value

    @property
    def status(self):
        """ the status of bulk record
        Corresponds to the 'Status' field in the bulk file.

        :rtype: str
        """
        return self._status

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

    @property
    def campaign(self):
        """ the id of the account which contains the feed
        Corresponds to the 'campaign' field in the bulk file.

        :rtype: str
        """
        return self._campaign

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

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

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self.convert_to_values(row_values, BulkFeedItem._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkFeedItem, self).read_additional_data(stream_reader)
예제 #25
0
class BulkRemarketingList(_SingleRecordBulkEntity):
    """ Represents an Remarketing List that can be read or written in a bulk file.

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

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

    *See also:*

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

        self._remarketing_list = remarketing_list
        self._status = status

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Id),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.ParentId),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'ParentId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Audience,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Name),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Name', v)),
        _SimpleBulkMapping(
            _StringTable.Description,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Description),
            csv_to_field=lambda c, v: setattr(c.remarketing_list,
                                              'Description', v)),
        _SimpleBulkMapping(_StringTable.MembershipDuration,
                           field_to_csv=lambda c: bulk_str(c.remarketing_list.
                                                           MembershipDuration),
                           csv_to_field=lambda c, v: setattr(
                               c.remarketing_list, 'MembershipDuration',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Scope,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Scope),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Scope', v
                                              if v else None)),
        _SimpleBulkMapping(
            _StringTable.TagId,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.TagId),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'TagId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.RemarketingRule,
            field_to_csv=lambda c: field_to_csv_RemarketingRule(
                c.remarketing_list),
            csv_to_field=lambda c, v: csv_to_field_RemarketingRule(
                c.remarketing_list, v)),
        _SimpleBulkMapping(
            _StringTable.AudienceSearchSize,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.SearchSize),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'SearchSize',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.AudienceNetworkSize,
                           field_to_csv=lambda c: bulk_str(
                               c.remarketing_list.AudienceNetworkSize),
                           csv_to_field=lambda c, v: setattr(
                               c.remarketing_list, 'AudienceNetworkSize', v
                               if v else None)),
        _SimpleBulkMapping(
            _StringTable.SupportedCampaignTypes,
            field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(
                c.remarketing_list.SupportedCampaignTypes),
            csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(
                c.remarketing_list.SupportedCampaignTypes, v)),
    ]

    @property
    def remarketing_list(self):
        """ Defines a Remarketing List """

        return self._remarketing_list

    @remarketing_list.setter
    def remarketing_list(self, remarketing_list):
        self._remarketing_list = remarketing_list

    @property
    def status(self):
        """ The status of the Remarketing List

        :rtype: str
        """

        return self._status

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

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.remarketing_list,
                                         'remarketing_list')
        self.convert_to_values(row_values, BulkRemarketingList._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._remarketing_list = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'RemarketingList')
        row_values.convert_to_entity(self, BulkRemarketingList._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkRemarketingList, self).read_additional_data(stream_reader)
예제 #26
0
class QualityScoreData(_BulkObject):
    """ Represents a subset of the fields available in bulk records that support quality score data.

    For example :class:`.BulkKeyword`. For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127.
    """
    def __init__(self):
        self._quality_score = None
        self._keyword_relevance = None
        self._landing_page_relevance = None
        self._landing_page_user_experience = None

    @property
    def quality_score(self):
        """ Corresponds to the 'Quality Score' field in the bulk file.

        :rtype: int
        """

        return self._quality_score

    @property
    def keyword_relevance(self):
        """ Corresponds to the 'Keyword Relevance' field in the bulk file.

        :rtype: int
        """

        return self._keyword_relevance

    @property
    def landing_page_relevance(self):
        """ Corresponds to the 'Landing Page Relevance' field in the bulk file.

        :rtype: int
        """

        return self._landing_page_relevance

    @property
    def landing_page_user_experience(self):
        """ Corresponds to the 'Landing Page User Experience' field in the bulk file.

        :rtype: int
        """

        return self._landing_page_user_experience

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.QualityScore,
            field_to_csv=lambda c: bulk_str(c.quality_score),
            csv_to_field=lambda c, v: setattr(c, '_quality_score',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.KeywordRelevance,
            field_to_csv=lambda c: bulk_str(c.keyword_relevance),
            csv_to_field=lambda c, v: setattr(c, '_keyword_relevance',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.LandingPageRelevance,
            field_to_csv=lambda c: bulk_str(c.landing_page_relevance),
            csv_to_field=lambda c, v: setattr(c, '_landing_page_relevance',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.LandingPageUserExperience,
            field_to_csv=lambda c: bulk_str(c.landing_page_user_experience),
            csv_to_field=lambda c, v: setattr(c,
                                              '_landing_page_user_experience',
                                              int(v) if v else None)),
    ]

    @staticmethod
    def read_from_row_values_or_null(row_values):
        quality_score_data = QualityScoreData()
        quality_score_data.read_from_row_values(row_values)
        return quality_score_data if quality_score_data.has_any_values else None

    @staticmethod
    def write_to_row_values_if_not_null(quality_score_data, row_values):
        if quality_score_data is not None:
            quality_score_data.write_to_row_values(row_values, False)

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, QualityScoreData._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, QualityScoreData._MAPPINGS)

    @property
    def has_any_values(self):
        return \
            self.quality_score \
            or self.keyword_relevance \
            or self.landing_page_relevance \
            or self.landing_page_user_experience

    def write_to_stream(self, row_writer, exclude_readonly_data):
        pass

    def read_related_data_from_stream(self, stream_reader):
        super(QualityScoreData,
              self).read_related_data_from_stream(stream_reader)

    def enclose_in_multiline_entity(self):
        pass

    @property
    def can_enclose_in_multiline_entity(self):
        return super(QualityScoreData, self).can_enclose_in_multiline_entity()
예제 #27
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 = [
        _SimpleBulkMapping(
            _StringTable.IsExcluded,
            field_to_csv=lambda c: 'True' if isinstance(c.ad_group_criterion, _NegativeAdGroupCriterion) else 'False',
            csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_is_excluded(c, v)
        ),
        _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.Bid,
            field_to_csv=lambda c: BulkAdGroupProductPartition._write_bid(c),
            csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_bid(c, 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)
예제 #28
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)
예제 #29
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)
예제 #30
0
class _BulkLabelAssociation(_SingleRecordBulkEntity):
    """ Represents a label association that can be read or written in a bulk file.

    This class exposes the :attr:`label_association` 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, label_association=None, status=None):
        super(_BulkLabelAssociation, self).__init__()
        self._label_association = label_association
        self._status = status

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

        A subset of Label properties are available in the Ad Group record.
        """

        return self._label_association

    @label_association.setter
    def label_association(self, value):
        self._label_association = value

    @property
    def status(self):
        """ the status of bulk record
        Corresponds to the 'Status' field in the bulk file.

        :rtype: str
        """
        return self._status

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

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.status),
            csv_to_field=lambda c, v: setattr(c, 'status', v if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: c.label_association.LabelId,
            csv_to_field=lambda c, v: setattr(c.label_association, 'LabelId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: c.label_association.EntityId,
            csv_to_field=lambda c, v: setattr(c.label_association, 'EntityId',
                                              int(v) if v else None)),
    ]

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self._label_association,
                                         'label_association')
        self.convert_to_values(row_values, _BulkLabelAssociation._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._label_association = _CAMPAIGN_OBJECT_FACTORY_V13.create(
            'LabelAssociation')
        row_values.convert_to_entity(self, _BulkLabelAssociation._MAPPINGS)

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