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)
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), 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_V11.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 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_V11.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)
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 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()
class BulkImageAdExtension(_BulkAdExtensionBase): """ Represents a image ad extension. This class exposes the :attr:`image_ad_extension` property that can be read and written as fields of the Image Ad Extension record in a bulk file. For more information, see Image 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, _ImageAdExtension): raise ValueError( 'The type of ad_extension is: {0}, should be: {1}'.format( type(ad_extension), 'ImageAdExtension')) super(BulkImageAdExtension, self).__init__(account_id=account_id, ad_extension=ad_extension) @property def image_ad_extension(self): """ The image ad extension. see Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._ad_extension @image_ad_extension.setter def image_ad_extension(self, value): self._ad_extension = value _MAPPINGS = [ _SimpleBulkMapping(header=_StringTable.DestinationUrl, field_to_csv=lambda c: bulk_optional_str( c.image_ad_extension.DestinationUrl), csv_to_field=lambda c, v: setattr( c.image_ad_extension, 'DestinationUrl', v if v else '')), _SimpleBulkMapping( header=_StringTable.AltText, field_to_csv=lambda c: c.image_ad_extension.AlternativeText, csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'AlternativeText', v)), _SimpleBulkMapping( header=_StringTable.MediaIds, #field_to_csv=lambda c: bulk_str(c.image_ad_extension.ImageMediaIds), field_to_csv=lambda c: field_to_csv_MediaIds(c.image_ad_extension), #csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'ImageMediaIds', int(v)) csv_to_field=lambda c, v: csv_to_field_MediaIds( c.image_ad_extension, v)), ] def process_mappings_from_row_values(self, row_values): self.image_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'ImageAdExtension') self.image_ad_extension.Type = 'ImageAdExtension' super(BulkImageAdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkImageAdExtension._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.image_ad_extension, 'image_ad_extension') super(BulkImageAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkImageAdExtension._MAPPINGS)
class BulkCampaignLocationCriterion(_SingleRecordBulkEntity): """ Represents an Campaign Location 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 Location Criterion record in a bulk file. For more information, see Campaign Location 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(BulkCampaignLocationCriterion, 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_LocationTarget( c.biddable_campaign_criterion), csv_to_field=lambda c, v: csv_to_field_LocationTarget( c.biddable_campaign_criterion, long(v) if v else None)), _SimpleBulkMapping(_StringTable.SubType, field_to_csv=lambda c: field_to_csv_LocationType( c.biddable_campaign_criterion), csv_to_field=lambda c, v: csv_to_field_LocationType( c.biddable_campaign_criterion, v)), _SimpleBulkMapping(_StringTable.Name, field_to_csv=lambda c: field_to_csv_LocationName( c.biddable_campaign_criterion), csv_to_field=lambda c, v: csv_to_field_LocationName( 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, BulkCampaignLocationCriterion._MAPPINGS) def process_mappings_from_row_values(self, row_values): self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'BiddableCampaignCriterion') self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'LocationCriterion') self._biddable_campaign_criterion.Criterion.Type = 'LocationCriterion' self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'BidMultiplier') self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' row_values.convert_to_entity(self, BulkCampaignLocationCriterion._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkCampaignLocationCriterion, self).read_additional_data(stream_reader)
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(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_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))), _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: _ProductConditionHelper.add_row_values_from_conditions( # c.campaign_criterion.Criterion.Conditions.ProductCondition, # v #), 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_V11.create( 'BiddableCampaignCriterion') self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.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)
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))), ] 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 _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 @property def performance_data(self): return self._performance_data _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) )), _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_V11.create( 'AdExtensionIdToEntityIdAssociation') row_values.convert_to_entity(self, _BulkAdExtensionAssociation._MAPPINGS) self._performance_data = PerformanceData.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_extension_id_to_entity_id_association, 'ad_extension_id_to_entity_id_association') self.convert_to_values(row_values, _BulkAdExtensionAssociation._MAPPINGS) if not exclude_readonly_data: PerformanceData.write_to_row_values_if_not_null( self.performance_data, row_values) def read_additional_data(self, stream_reader): super(_BulkAdExtensionAssociation, self).read_additional_data(stream_reader)
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 @property def performance_data(self): """ The historical performance data corresponding to the suggested bid. :rtype: PerformanceData """ return self._performance_data _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) self._performance_data = PerformanceData.read_from_row_values( row_values) def write_to_row_values(self, row_values, exclude_readonly_data): self.convert_to_values(row_values, BulkKeywordBidSuggestion._MAPPINGS) if not exclude_readonly_data: PerformanceData.write_to_row_values_if_not_null( self.performance_data, row_values) @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)
class BulkDynamicSearchAd(_BulkAd): """ Represents a Dynamic Search Ad. This class exposes the :attr:`dynamic_search_ad` property that can be read and written as fields of the Dynamic Search Ad record in a bulk file. For more information, see Dynamic 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(BulkDynamicSearchAd, self).__init__( ad_group_id, campaign_name, ad_group_name, ad, ) self.dynamic_search_ad = ad @property def dynamic_search_ad(self): """ The dynamic search ad. see Dynamic Search Ad at https://go.microsoft.com/fwlink/?linkid=836840. """ return self._ad @dynamic_search_ad.setter def dynamic_search_ad(self, dynamic_search_ad): if dynamic_search_ad is not None and not isinstance( dynamic_search_ad, DynamicSearchAd): raise ValueError('Not an instance of DynamicSearchAd') self._ad = dynamic_search_ad _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Text, field_to_csv=lambda c: c.dynamic_search_ad.Text, csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Text', v)), _SimpleBulkMapping(header=_StringTable.Path1, field_to_csv=lambda c: c.dynamic_search_ad.Path1, csv_to_field=lambda c, v: setattr( c.dynamic_search_ad, 'Path1', v)), _SimpleBulkMapping(header=_StringTable.Path2, field_to_csv=lambda c: c.dynamic_search_ad.Path2, csv_to_field=lambda c, v: setattr( c.dynamic_search_ad, 'Path2', v)), ] def process_mappings_from_row_values(self, row_values): self.dynamic_search_ad = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'DynamicSearchAd') self.dynamic_search_ad.Type = 'DynamicSearch' super(BulkDynamicSearchAd, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkDynamicSearchAd._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.dynamic_search_ad, 'dynamic_search_ad') super(BulkDynamicSearchAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkDynamicSearchAd._MAPPINGS)
class BulkAppInstallAd(_BulkAd): """ Represents an App Install Ad. This class exposes the :attr:`app_install_ad` property that can be read and written as fields of the App Install Ad record in a bulk file. For more information, see App Install 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(BulkAppInstallAd, self).__init__( ad_group_id, campaign_name, ad_group_name, ad, ) self.app_install_ad = ad @property def app_install_ad(self): """ The App Install Ad. see App Install Ad at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._ad @app_install_ad.setter def app_install_ad(self, app_install_ad): if app_install_ad is not None and not isinstance( app_install_ad, AppInstallAd): raise ValueError('Not an instance of AppInstallAd') self._ad = app_install_ad _MAPPINGS = [ _SimpleBulkMapping(header=_StringTable.AppPlatform, field_to_csv=lambda c: c.app_install_ad.AppPlatform, csv_to_field=lambda c, v: setattr( c.app_install_ad, 'AppPlatform', v)), _SimpleBulkMapping(header=_StringTable.AppStoreId, field_to_csv=lambda c: c.app_install_ad.AppStoreId, csv_to_field=lambda c, v: setattr( c.app_install_ad, 'AppStoreId', v)), _SimpleBulkMapping( header=_StringTable.Title, field_to_csv=lambda c: c.app_install_ad.Title, csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Title', v)), _SimpleBulkMapping( header=_StringTable.Text, field_to_csv=lambda c: c.app_install_ad.Text, csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Text', v)), ] def process_mappings_from_row_values(self, row_values): self.app_install_ad = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'AppInstallAd') self.app_install_ad.Type = 'AppInstall' super(BulkAppInstallAd, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkAppInstallAd._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.app_install_ad, 'app_install_ad') super(BulkAppInstallAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkAppInstallAd._MAPPINGS)
class _BulkAd(_SingleRecordBulkEntity): """ This abstract base class provides properties that are shared by all bulk ad classes. *See also:* * :class:`.BulkProductAd` * :class:`.BulkTextAd` * :class:`.BulkAppInstallAd` * :class:`.BulkExpandedTextAd` * :class:`.BulkDynamicSearchAd` """ def __init__(self, ad_group_id=None, campaign_name=None, ad_group_name=None, ad=None): super(_BulkAd, self).__init__() self._ad_group_id = ad_group_id self._campaign_name = campaign_name self._ad_group_name = ad_group_name self._ad = ad self._performance_data = None @property def ad_group_id(self): """ The identifier of the ad group that contains the ad. 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 campaign_name(self): """ The name of the campaign that contains the ad. 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 ad. 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 ad(self): """ The type of ad. """ return self._ad @ad.setter def ad(self, ad): self._ad = ad @property def performance_data(self): """ The historical performance data for the ad. :rtype: PerformanceData """ return self._performance_data _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Status, field_to_csv=lambda c: bulk_str(c.ad.Status), csv_to_field=lambda c, v: setattr(c.ad, 'Status', v if v else None)), _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.ad.Id), csv_to_field=lambda c, v: setattr(c.ad, '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.EditorialStatus, field_to_csv=lambda c: c.ad.EditorialStatus, csv_to_field=lambda c, v: setattr(c.ad, 'EditorialStatus', v if v else None)), _SimpleBulkMapping( header=_StringTable.DevicePreference, field_to_csv=lambda c: bulk_device_preference_str( c.ad.DevicePreference), csv_to_field=lambda c, v: setattr(c.ad, 'DevicePreference', parse_device_preference(v))), _SimpleBulkMapping( header=_StringTable.FinalUrl, field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalUrls), csv_to_field=lambda c, v: csv_to_field_Urls(c.ad.FinalUrls, v)), _SimpleBulkMapping( header=_StringTable.FinalMobileUrl, field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalMobileUrls), csv_to_field=lambda c, v: csv_to_field_Urls( c.ad.FinalMobileUrls, v)), _SimpleBulkMapping( header=_StringTable.TrackingTemplate, field_to_csv=lambda c: bulk_str(c.ad.TrackingUrlTemplate), csv_to_field=lambda c, v: setattr(c.ad, 'TrackingUrlTemplate', v if v else None)), _SimpleBulkMapping( header=_StringTable.CustomParameter, field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad), csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters( c.ad, v)), # TODO FinalAppUrls is not added ] def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self.convert_to_values(row_values, _BulkAd._MAPPINGS) if not exclude_readonly_data: PerformanceData.write_to_row_values_if_not_null( self.performance_data, row_values) def process_mappings_from_row_values(self, row_values): row_values.convert_to_entity(self, _BulkAd._MAPPINGS) self._performance_data = PerformanceData.read_from_row_values_or_null( row_values) def read_additional_data(self, stream_reader): super(_BulkAd, self).read_additional_data(stream_reader)
class BulkCampaign(_SingleRecordBulkEntity): """ Represents a campaign that can be read or written in a bulk file. This class exposes the :attr:`campaign` property that can be read and written as fields of the Campaign record in a bulk file. For more information, see Campaign at https://go.microsoft.com/fwlink/?linkid=846127. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, account_id=None, campaign=None): super(BulkCampaign, self).__init__() self._account_id = account_id self._campaign = campaign self._quality_score_data = None self._performance_data = None self._budget_name = None @property def account_id(self): """ The identifier of the account that contains the campaign. Corresponds to the 'Parent Id' field in the bulk file. :rtype: int """ return self._account_id @account_id.setter def account_id(self, account_id): self._account_id = account_id @property def budget_name(self): """ The budget name that the campaign associated, only for campaigns that use a shared budget Corresponds to 'Budget Name' field in bulk file. :rtype: str """ return self._budget_name @budget_name.setter def budget_name(self, value): self._budget_name = value @property def campaign(self): """ Defines a campaign within an account. See Campaign at https://docs.microsoft.com/en-us/bingads/campaign-management-service/campaign?view=bingads-12 """ return self._campaign @campaign.setter def campaign(self, campaign): self._campaign = campaign @property def quality_score_data(self): """ The quality score data for the campaign. :rtype: QualityScoreData """ return self._quality_score_data @property def performance_data(self): """ The historical performance data for the campaign :rtype: PerformanceData """ return self._performance_data def _get_shopping_setting(self): if not self.campaign.Settings.Setting: return None shopping_settings = [ setting for setting in self.campaign.Settings.Setting if isinstance(setting, _ShoppingSetting) ] if len(shopping_settings) != 1: raise ValueError( 'Can only have 1 ShoppingSetting in Campaign Settings.') return shopping_settings[0] @staticmethod def _write_campaign_type(c): if not c.campaign.CampaignType: return None if len(c.campaign.CampaignType) != 1: raise ValueError("Only 1 CampaignType can be set in Campaign") return c.campaign.CampaignType[0] @staticmethod def _read_campaign_type(c, v): if not v: return [] campaign_type = v c.campaign.CampaignType = [campaign_type] if campaign_type.lower() == 'shopping' or campaign_type.lower( ) == 'audience': c.campaign.Settings = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'ArrayOfSetting') shopping_setting = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'ShoppingSetting') shopping_setting.Type = 'ShoppingSetting' c.campaign.Settings.Setting = [shopping_setting] @staticmethod def _write_store_id(c): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None return bulk_str(shopping_setting.StoreId) @staticmethod def _read_store_id(c, v): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None shopping_setting.StoreId = int(v) if v else None @staticmethod def _write_priority(c): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None return bulk_str(shopping_setting.Priority) @staticmethod def _read_priority(c, v): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None shopping_setting.Priority = int(v) if v else None @staticmethod def _write_sales_country_code(c): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None return shopping_setting.SalesCountryCode @staticmethod def _read_sales_country_code(c, v): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None shopping_setting.SalesCountryCode = v @staticmethod def _write_local_inventory_ads_enabled(c): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None return shopping_setting.LocalInventoryAdsEnabled @staticmethod def _read_local_inventory_ads_enabled(c, v): if not c.campaign.CampaignType: return None campgaign_types = [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ] if 'shopping' in campgaign_types or 'audience' in campgaign_types: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None shopping_setting.LocalInventoryAdsEnabled = v.lower( ) == 'true' if v else None _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.CampaignType, field_to_csv=lambda c: BulkCampaign._write_campaign_type(c), csv_to_field=lambda c, v: BulkCampaign._read_campaign_type(c, v)), _SimpleBulkMapping( header=_StringTable.Status, field_to_csv=lambda c: bulk_str(c.campaign.Status), csv_to_field=lambda c, v: setattr(c.campaign, 'Status', v if v else None)), _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.campaign.Id), csv_to_field=lambda c, v: setattr(c.campaign, 'Id', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.ParentId, field_to_csv=lambda c: bulk_str(c.account_id), csv_to_field=lambda c, v: setattr(c, '_account_id', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.Campaign, field_to_csv=lambda c: c.campaign.Name, csv_to_field=lambda c, v: setattr(c.campaign, 'Name', v)), _SimpleBulkMapping( header=_StringTable.TimeZone, field_to_csv=lambda c: c.campaign.TimeZone, csv_to_field=lambda c, v: setattr(c.campaign, 'TimeZone', v)), _SimpleBulkMapping( header=_StringTable.Language, field_to_csv=lambda c: field_to_csv_CampaignLanguages(c.campaign. Languages), csv_to_field=lambda c, v: csv_to_field_CampaignLanguages( c.campaign.Languages, v)), _ComplexBulkMapping(budget_to_csv, csv_to_budget), _SimpleBulkMapping( header=_StringTable.BidAdjustment, field_to_csv=lambda c: bulk_str(c.campaign.NativeBidAdjustment), csv_to_field=lambda c, v: setattr(c.campaign, 'NativeBidAdjustment', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.BingMerchantCenterId, field_to_csv=lambda c: BulkCampaign._write_store_id(c), csv_to_field=lambda c, v: BulkCampaign._read_store_id(c, v)), _SimpleBulkMapping( header=_StringTable.CampaignPriority, field_to_csv=lambda c: BulkCampaign._write_priority(c), csv_to_field=lambda c, v: BulkCampaign._read_priority(c, v)), _SimpleBulkMapping( header=_StringTable.CountryCode, field_to_csv=lambda c: BulkCampaign._write_sales_country_code(c), csv_to_field=lambda c, v: BulkCampaign._read_sales_country_code( c, v)), _SimpleBulkMapping(header=_StringTable.LocalInventoryAdsEnabled, field_to_csv=lambda c: BulkCampaign. _write_local_inventory_ads_enabled(c), csv_to_field=lambda c, v: BulkCampaign. _read_local_inventory_ads_enabled(c, v)), _SimpleBulkMapping( header=_StringTable.TrackingTemplate, field_to_csv=lambda c: bulk_str(c.campaign.TrackingUrlTemplate), csv_to_field=lambda c, v: setattr( c.campaign, 'TrackingUrlTemplate', v if v else None)), _SimpleBulkMapping(header=_StringTable.CustomParameter, field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.campaign), csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.campaign, v)), _ComplexBulkMapping(biddingscheme_to_csv, csv_to_biddingscheme), _SimpleBulkMapping( header=_StringTable.BudgetId, field_to_csv=lambda c: bulk_str(c.campaign.BudgetId), csv_to_field=lambda c, v: setattr(c.campaign, 'BudgetId', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.BudgetType, field_to_csv=lambda c: bulk_str(c.campaign.BudgetType), csv_to_field=lambda c, v: csv_to_field_BudgetType( c.campaign, v, version=11)), _SimpleBulkMapping( header=_StringTable.BudgetName, field_to_csv=lambda c: bulk_str(c.budget_name), csv_to_field=lambda c, v: setattr(c, 'budget_name', v if v else None)), _SimpleBulkMapping( header=_StringTable.Website, field_to_csv=lambda c: field_to_csv_DSAWebsite(c.campaign), csv_to_field=lambda c, v: csv_to_field_DSAWebsite(c.campaign, v)), _SimpleBulkMapping( header=_StringTable.DomainLanguage, field_to_csv=lambda c: field_to_csv_DSADomainLanguage(c.campaign), csv_to_field=lambda c, v: csv_to_field_DSADomainLanguage( c.campaign, v)), ] def read_additional_data(self, stream_reader): super(BulkCampaign, self).read_additional_data(stream_reader) def process_mappings_from_row_values(self, row_values): self._campaign = _CAMPAIGN_OBJECT_FACTORY_V11.create('Campaign') row_values.convert_to_entity(self, BulkCampaign._MAPPINGS) self._quality_score_data = QualityScoreData.read_from_row_values_or_null( row_values) self._performance_data = PerformanceData.read_from_row_values_or_null( row_values) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.campaign, 'campaign') self.convert_to_values(row_values, BulkCampaign._MAPPINGS) if not exclude_readonly_data: QualityScoreData.write_to_row_values_if_not_null( self.quality_score_data, row_values) PerformanceData.write_to_row_values_if_not_null( self.performance_data, row_values)
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._performance_data = None 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-12 """ 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 performance_data(self): """ The historical performance data for the keyword. :rtype: PerformanceData """ return self._performance_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), csv_to_field=lambda c, v: setattr( c.keyword, 'DestinationUrl', v if v else '' ) ), _SimpleBulkMapping( header=_StringTable.Bid, field_to_csv=lambda c: keyword_bid_bulk_str(c.keyword.Bid), 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), 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), 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), 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), 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), 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), ] 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) PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) def process_mappings_from_row_values(self, row_values): self._keyword = _CAMPAIGN_OBJECT_FACTORY_V11.create('Keyword') row_values.convert_to_entity(self, BulkKeyword._MAPPINGS) self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values) self._performance_data = PerformanceData.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 BulkAdGroupNegativeKeyword(_BulkEntityNegativeKeyword): """ Represents a negative keyword that is assigned to a ad group. Each negative keyword can be read or written in a bulk file. This class exposes the :attr:`.BulkNegativeKeyword.negative_keyword` property that can be read and written as fields of the Ad Group Negative Keyword record in a bulk file. For more information, see Ad Group Negative Keyword at https://go.microsoft.com/fwlink/?linkid=846127. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, status=None, negative_keyword=None, ad_group_id=None, ad_group_name=None, campaign_name=None): super(BulkAdGroupNegativeKeyword, self).__init__( status, negative_keyword, ad_group_id, ad_group_name, ) self._campaign_name = campaign_name @property def campaign_name(self): """ The name of the campaign that the negative keyword is assigned. 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_id(self): """ Corresponds to the 'Parent Id' field in the bulk file. :return: The identifier of the ad group that the negative keyword is assigned. :rtype: int """ return self._parent_id @ad_group_id.setter def ad_group_id(self, value): self._parent_id = value @property def ad_group_name(self): """ Corresponds to the 'Ad Group' field in the bulk file. :return: The name of the ad group that the negative keyword is assigned. :rtype: str """ return self._entity_name @ad_group_name.setter def ad_group_name(self, value): self._entity_name = value @property def _entity_column_name(self): return _StringTable.AdGroup _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 process_mappings_to_row_values(self, row_values, exclude_readonly_data): super(BulkAdGroupNegativeKeyword, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkAdGroupNegativeKeyword._MAPPINGS) def process_mappings_from_row_values(self, row_values): super(BulkAdGroupNegativeKeyword, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkAdGroupNegativeKeyword._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkAdGroupNegativeKeyword, self).read_additional_data(stream_reader)
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))), _SimpleBulkMapping( header=_StringTable.StartDate, field_to_csv=lambda c: field_to_csv_SchedulingStartDate( c._ad_extension.Scheduling), 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_SchedulingEndDate( c._ad_extension.Scheduling), 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), 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), 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)
class BulkCampaignNegativeKeywordList(_SingleRecordBulkEntity): """ Represents a negative keyword list that is assigned to a campaign. Each negative keyword list can be read or written in a bulk file. This class exposes the :attr:`BulkCampaignNegativeKeywordList.SharedEntityAssociation` property that can be read and written as fields of the Campaign Negative Keyword List Association record in a bulk file. For more information, see Campaign Negative Keyword List Association at https://go.microsoft.com/fwlink/?linkid=846127. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, status=None, shared_entity_association=None): super(BulkCampaignNegativeKeywordList, self).__init__() self._shared_entity_association = shared_entity_association self._status = status @property def status(self): """ The status of the negative keyword list association. :rtype: str """ return self._status @status.setter def status(self, status): self._status = status @property def shared_entity_association(self): """ The campaign and negative keyword list identifiers. see Campaign Negative Keyword List Association at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._shared_entity_association @shared_entity_association.setter def shared_entity_association(self, shared_entity_association): self._shared_entity_association = shared_entity_association _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Status, field_to_csv=lambda c: 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.shared_entity_association. SharedEntityId), csv_to_field=lambda c, v: setattr(c.shared_entity_association, 'SharedEntityId', int(v))), _SimpleBulkMapping( header=_StringTable.ParentId, field_to_csv=lambda c: bulk_str(c.shared_entity_association. EntityId), csv_to_field=lambda c, v: setattr(c.shared_entity_association, 'EntityId', int(v))), ] def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self._shared_entity_association, 'shared_entity_association') self.convert_to_values(row_values, BulkCampaignNegativeKeywordList._MAPPINGS) def process_mappings_from_row_values(self, row_values): self._shared_entity_association = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'SharedEntityAssociation') self._shared_entity_association.EntityType = 'Campaign' self._shared_entity_association.SharedEntityType = 'NegativeKeywordList' row_values.convert_to_entity(self, BulkCampaignNegativeKeywordList._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkCampaignNegativeKeywordList, self).read_additional_data(stream_reader)
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 @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 _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)), ] 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 BulkNegativeKeywordList(_SingleRecordBulkEntity): """ Represents a negative keyword list that can be read or written in a bulk file. This class exposes the :attr:`.BulkNegativeKeywordList.negative_keyword_list` property that can be read and written as fields of the Negative Keyword List record in a bulk file. For more information, see Negative Keyword List at https://go.microsoft.com/fwlink/?linkid=846127. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, status=None, negative_keyword_list=None): super(BulkNegativeKeywordList, self).__init__() self._status = status self._negative_keyword_list = negative_keyword_list @property def negative_keyword_list(self): """ The negative keyword list. see Negative Keyword List at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._negative_keyword_list @negative_keyword_list.setter def negative_keyword_list(self, negative_keyword_list): self._negative_keyword_list = negative_keyword_list @property def status(self): """ The status of the negative keyword list. :rtype: str """ return self._status @status.setter def status(self, status): self._status = status _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.negative_keyword_list.Id), csv_to_field=lambda c, v: setattr(c.negative_keyword_list, 'Id', int(v) if v else None)), _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.Name, field_to_csv=lambda c: c.negative_keyword_list.Name, csv_to_field=lambda c, v: setattr( c.negative_keyword_list, 'Name', v)) ] def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self._negative_keyword_list, 'negative_keyword_list') self.convert_to_values(row_values, BulkNegativeKeywordList._MAPPINGS) def process_mappings_from_row_values(self, row_values): self._negative_keyword_list = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'NegativeKeywordList') self._negative_keyword_list.Type = 'NegativeKeywordList' row_values.convert_to_entity(self, BulkNegativeKeywordList._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkNegativeKeywordList, self).read_additional_data(stream_reader)
class BulkSitelink2AdExtension(_BulkAdExtensionBase): """ Represents a sitelink2 ad extension. This class exposes the :attr:`sitelink2_ad_extension` property that can be read and written as fields of the Sitelink2 Ad Extension record in a bulk file. For more information, see Sitelink2 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, _Sitelink2AdExtension): raise ValueError( 'The type of ad_extension is: {0}, should be: {1}'.format( type(ad_extension), 'Sitelink2AdExtension')) super(BulkSitelink2AdExtension, self).__init__(account_id=account_id, ad_extension=ad_extension) @property def sitelink2_ad_extension(self): """ The sitelink2 ad extension. see Sitelink2 Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._ad_extension @sitelink2_ad_extension.setter def sitelink2_ad_extension(self, value): self._ad_extension = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.SiteLinkDescription1, field_to_csv=lambda c: c.sitelink2_ad_extension.Description1, csv_to_field=lambda c, v: setattr(c.sitelink2_ad_extension, 'Description1', v)), _SimpleBulkMapping( header=_StringTable.SiteLinkDescription2, field_to_csv=lambda c: c.sitelink2_ad_extension.Description2, csv_to_field=lambda c, v: setattr(c.sitelink2_ad_extension, 'Description2', v)), _SimpleBulkMapping(header=_StringTable.DestinationUrl, field_to_csv=lambda c: bulk_optional_str( c.sitelink2_ad_extension.DestinationUrl), csv_to_field=lambda c, v: setattr( c.sitelink2_ad_extension, 'DestinationUrl', v if v else '')), _SimpleBulkMapping(header=_StringTable.DevicePreference, field_to_csv=lambda c: bulk_device_preference_str( c.sitelink2_ad_extension.DevicePreference), csv_to_field=lambda c, v: setattr( c.sitelink2_ad_extension, 'DevicePreference', parse_device_preference(v))), _SimpleBulkMapping( header=_StringTable.SiteLinkDisplayText, field_to_csv=lambda c: c.sitelink2_ad_extension.DisplayText, csv_to_field=lambda c, v: setattr(c.sitelink2_ad_extension, 'DisplayText', v)), _SimpleBulkMapping(header=_StringTable.FinalUrl, field_to_csv=lambda c: field_to_csv_Urls( c.sitelink2_ad_extension.FinalUrls), csv_to_field=lambda c, v: csv_to_field_Urls( c.sitelink2_ad_extension.FinalUrls, v)), _SimpleBulkMapping(header=_StringTable.FinalMobileUrl, field_to_csv=lambda c: field_to_csv_Urls( c.sitelink2_ad_extension.FinalMobileUrls), csv_to_field=lambda c, v: csv_to_field_Urls( c.sitelink2_ad_extension.FinalMobileUrls, v)), _SimpleBulkMapping( header=_StringTable.TrackingTemplate, field_to_csv=lambda c: bulk_str(c.sitelink2_ad_extension. TrackingUrlTemplate), csv_to_field=lambda c, v: setattr(c.sitelink2_ad_extension, 'TrackingUrlTemplate', v if v else None)), _SimpleBulkMapping( header=_StringTable.CustomParameter, field_to_csv=lambda c: field_to_csv_UrlCustomParameters( c.sitelink2_ad_extension), csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters( c.sitelink2_ad_extension, v)), ] def process_mappings_from_row_values(self, row_values): self.sitelink2_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'Sitelink2AdExtension') self.sitelink2_ad_extension.Type = 'Sitelink2AdExtension' super(BulkSitelink2AdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkSitelink2AdExtension._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.sitelink2_ad_extension, 'sitelink2_ad_extension') super(BulkSitelink2AdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkSitelink2AdExtension._MAPPINGS)
class _BulkNegativeKeyword(_SingleRecordBulkEntity): """ The base class for all bulk negative keywords. Either assigned individually to a campaign or ad group entity, or shared in a negative keyword list. *See also:* * :class:`.BulkAdGroupNegativeKeyword` * :class:`.BulkCampaignNegativeKeyword` * :class:`.BulkSharedNegativeKeyword` """ def __init__(self, status=None, negative_keyword=None, parent_id=None): super(_BulkNegativeKeyword, self).__init__() self._negative_keyword = negative_keyword self._status = status self._parent_id = parent_id @property def status(self): """ The status of the negative keyword association. The value is 'Active' if the negative keyword is assigned to the parent entity. The value is 'Deleted' if the negative keyword is removed from the parent entity, or should be removed in a subsequent upload operation. :rtype: str """ return self._status @status.setter def status(self, status): self._status = status @property def negative_keyword(self): """ Defines a negative keyword with match type. """ return self._negative_keyword @negative_keyword.setter def negative_keyword(self, negative_keyword): self._negative_keyword = negative_keyword _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.negative_keyword.Id), csv_to_field=lambda c, v: setattr(c.negative_keyword, 'Id', int(v) if v else None)), _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._parent_id), csv_to_field=lambda c, v: setattr(c, '_parent_id', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.Keyword, field_to_csv=lambda c: c.negative_keyword.Text, csv_to_field=lambda c, v: setattr(c.negative_keyword, 'Text', v)), _SimpleBulkMapping( header=_StringTable.MatchType, field_to_csv=lambda c: bulk_str(c.negative_keyword.MatchType), csv_to_field=lambda c, v: setattr(c.negative_keyword, 'MatchType', v)) ] def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self._negative_keyword, 'negative_keyword') self.convert_to_values(row_values, _BulkNegativeKeyword._MAPPINGS) def process_mappings_from_row_values(self, row_values): self._negative_keyword = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'NegativeKeyword') self._negative_keyword.Type = 'NegativeKeyword' row_values.convert_to_entity(self, _BulkNegativeKeyword._MAPPINGS) def read_additional_data(self, stream_reader): super(_BulkNegativeKeyword, self).read_additional_data(stream_reader)
class BulkAdGroupNegativeRemarketingListAssociation(_SingleRecordBulkEntity): """ Represents an Ad Group Negative Remarketing List Association that can be read or written in a bulk file. This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the Ad Group Negative Remarketing List Association record in a bulk file. For more information, see Ad Group Negative Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, negative_ad_group_criterion=None, campaign_name=None, ad_group_name=None, remarketing_list_name=None): super(BulkAdGroupNegativeRemarketingListAssociation, self).__init__() self._negative_ad_group_criterion = negative_ad_group_criterion self._campaign_name = campaign_name self._ad_group_name = ad_group_name self._remarketing_list_name = remarketing_list_name _MAPPINGS = [ _SimpleBulkMapping(_StringTable.Status, field_to_csv=lambda c: bulk_str( c.negative_ad_group_criterion.Status), csv_to_field=lambda c, v: setattr( c.negative_ad_group_criterion, 'Status', v if v else None)), _SimpleBulkMapping( _StringTable.Id, field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None)), _SimpleBulkMapping(_StringTable.ParentId, field_to_csv=lambda c: bulk_str( c.negative_ad_group_criterion.AdGroupId), csv_to_field=lambda c, v: setattr( c.negative_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.Audience, field_to_csv=lambda c: c.remarketing_list_name, csv_to_field=lambda c, v: setattr(c, 'remarketing_list_name', v)), _SimpleBulkMapping( _StringTable.AudienceId, field_to_csv=lambda c: field_to_csv_CriterionAudienceId( c.negative_ad_group_criterion), csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId( c.negative_ad_group_criterion, int(v) if v else None)), ] @property def negative_ad_group_criterion(self): """ Defines a Negative Ad Group Criterion """ return self._negative_ad_group_criterion @negative_ad_group_criterion.setter def negative_ad_group_criterion(self, negative_ad_group_criterion): self._negative_ad_group_criterion = negative_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 @property def remarketing_list_name(self): """ Defines the name of the Remarketing List :rtype: str """ return self._remarketing_list_name @remarketing_list_name.setter def remarketing_list_name(self, remarketing_list_name): self._remarketing_list_name = remarketing_list_name def process_mappings_from_row_values(self, row_values): self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'NegativeAdGroupCriterion') self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'AudienceCriterion') self._negative_ad_group_criterion.Criterion.Type = 'AudienceCriterion' row_values.convert_to_entity( self, BulkAdGroupNegativeRemarketingListAssociation._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') self.convert_to_values( row_values, BulkAdGroupNegativeRemarketingListAssociation._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkAdGroupNegativeRemarketingListAssociation, self).read_additional_data(stream_reader)
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)), ] @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_V11.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)
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), 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)), ] @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 @property def performance_data(self): return self._performance_data def process_mappings_from_row_values(self, row_values): self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'BiddableAdGroupCriterion') self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'ns0:Webpage') self._biddable_ad_group_criterion.Criterion.Type = 'Webpage' self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'FixedBid') self._biddable_ad_group_criterion.CriterionBid.Type = 'FixedBid' row_values.convert_to_entity( self, BulkAdGroupDynamicSearchAdTarget._MAPPINGS) self._performance_data = PerformanceData.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.biddable_ad_group_criterion, 'biddable_ad_group_criterion') self.convert_to_values(row_values, BulkAdGroupDynamicSearchAdTarget._MAPPINGS) PerformanceData.write_to_row_values_if_not_null( self._performance_data, row_values) def read_additional_data(self, stream_reader): super(BulkAdGroupDynamicSearchAdTarget, self).read_additional_data(stream_reader)
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._is_expired = None 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 is_expired(self): """ Indicates whether the AdGroup is expired. :rtype: bool """ return self._is_expired @property def quality_score_data(self): """ The quality score data for the ad group. :rtype: QualityScoreData """ return self._quality_score_data @property def performance_data(self): """ The historical performance data for the ad group. :rtype: PerformanceData """ return self._performance_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: 'Expired' if c.is_expired else 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.PricingModel, field_to_csv=lambda c: bulk_upper_str(c.ad_group.PricingModel), csv_to_field=lambda c, v: setattr(c.ad_group, 'PricingModel', v.title() if v else None)), _SimpleBulkMapping( header=_StringTable.AdRotation, field_to_csv=lambda c: ad_rotation_bulk_str(c.ad_group.AdRotation), csv_to_field=lambda c, v: setattr(c.ad_group, 'AdRotation', parse_ad_rotation(v))), _SimpleBulkMapping( header=_StringTable.SearchNetwork, field_to_csv=lambda c: None if not c.ad_group.AdDistribution else 'On' if 'Search' in c.ad_group.AdDistribution else 'Off', csv_to_field=lambda c, v: v == 'On' and setattr( c.ad_group, 'AdDistribution', (c.ad_group.AdDistribution + ' ' + 'Search').strip())), _SimpleBulkMapping( header=_StringTable.ContentNetwork, field_to_csv=lambda c: None if not c.ad_group.AdDistribution else 'On' if 'Content' in c.ad_group.AdDistribution else 'Off', csv_to_field=lambda c, v: v == 'On' and setattr( c.ad_group, 'AdDistribution', (c.ad_group.AdDistribution + ' ' + 'Content').strip())), _SimpleBulkMapping( header=_StringTable.SearchBid, field_to_csv=lambda c: ad_group_bid_bulk_str(c.ad_group.SearchBid), csv_to_field=lambda c, v: setattr(c.ad_group, 'SearchBid', parse_ad_group_bid(v))), _SimpleBulkMapping( header=_StringTable.ContentBid, field_to_csv=lambda c: ad_group_bid_bulk_str(c.ad_group. ContentMatchBid), csv_to_field=lambda c, v: setattr(c.ad_group, 'ContentMatchBid', 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.NativeBidAdjustment), csv_to_field=lambda c, v: setattr(c.ad_group, 'NativeBidAdjustment', 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)), _SimpleBulkMapping( header=_StringTable.BidStrategyType, field_to_csv=lambda c: field_to_csv_BidStrategyType(c.ad_group), csv_to_field=lambda c, v: csv_to_field_BidStrategyType( c.ad_group, v)), _SimpleBulkMapping(header=_StringTable.RemarketingTargetingSetting, field_to_csv=lambda c: bulk_str( c.ad_group.RemarketingTargetingSetting), csv_to_field=lambda c, v: setattr( c.ad_group, 'RemarketingTargetingSetting', v if v else None)), ] def process_mappings_from_row_values(self, row_values): self.ad_group = _CAMPAIGN_OBJECT_FACTORY_V11.create('AdGroup') self.ad_group.AdDistribution = '' row_values.convert_to_entity(self, BulkAdGroup._MAPPINGS) self._quality_score_data = QualityScoreData.read_from_row_values_or_null( row_values) self._performance_data = PerformanceData.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) PerformanceData.write_to_row_values_if_not_null( self.performance_data, row_values) def read_additional_data(self, stream_reader): super(BulkAdGroup, self).read_additional_data(stream_reader)
class PerformanceData(_BulkObject): """ Represents a subset of the fields available in bulk records that support historical performance data. For example :class:`.BulkKeyword`. For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. """ def __init__(self): self._spend = None self._impressions = None self._clicks = None self._click_through_rate = None self._average_cost_per_click = None self._average_cost_per_thousand_impressions = None self._average_position = None self._conversions = None self._cost_per_conversion = None @property def spend(self): """ Corresponds to the 'Spend' field in the bulk file. :rtype: float """ return self._spend @property def impressions(self): """ Corresponds to the 'Impressions' field in the bulk file. :rtype: int """ return self._impressions @property def clicks(self): """ Corresponds to the 'Clicks' field in the bulk file. :rtype: int """ return self._clicks @property def click_through_rate(self): """ Corresponds to the 'CTR' field in the bulk file. :rtype: float """ return self._click_through_rate @property def average_cost_per_click(self): """ Corresponds to the 'Avg CPC' field in the bulk file. :rtype: float """ return self._average_cost_per_click @property def average_cost_per_thousand_impressions(self): """ Corresponds to the 'Avg CPM' field in the bulk file. :rtype: float """ return self._average_cost_per_thousand_impressions @property def average_position(self): """ Corresponds to the 'Avg position' field in the bulk file. :rtype: float """ return self._average_position @property def conversions(self): """ Corresponds to the 'Conversions' field in the bulk file. :rtype: int """ return self._conversions @property def cost_per_conversion(self): """ Corresponds to the 'CPA' field in the bulk file. :rtype: float """ return self._cost_per_conversion _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Spend, field_to_csv=lambda c: bulk_str(c.spend), csv_to_field=lambda c, v: setattr(c, '_spend', float(v) if v else None)), _SimpleBulkMapping( header=_StringTable.Impressions, field_to_csv=lambda c: bulk_str(c.impressions), csv_to_field=lambda c, v: setattr(c, '_impressions', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.Clicks, field_to_csv=lambda c: bulk_str(c.clicks), csv_to_field=lambda c, v: setattr(c, '_clicks', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.CTR, field_to_csv=lambda c: bulk_str(c.click_through_rate), csv_to_field=lambda c, v: setattr(c, '_click_through_rate', float(v) if v else None)), _SimpleBulkMapping( header=_StringTable.AvgCPC, field_to_csv=lambda c: bulk_str(c.average_cost_per_click), csv_to_field=lambda c, v: setattr(c, '_average_cost_per_click', float(v) if v else None)), _SimpleBulkMapping(header=_StringTable.AvgCPM, field_to_csv=lambda c: bulk_str( c.average_cost_per_thousand_impressions), csv_to_field=lambda c, v: setattr( c, '_average_cost_per_thousand_impressions', float(v) if v else None)), _SimpleBulkMapping( header=_StringTable.AvgPosition, field_to_csv=lambda c: bulk_str(c.average_position), csv_to_field=lambda c, v: setattr(c, '_average_position', float(v) if v else None)), _SimpleBulkMapping( header=_StringTable.Conversions, field_to_csv=lambda c: bulk_str(c.conversions), csv_to_field=lambda c, v: setattr(c, '_conversions', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.CPA, field_to_csv=lambda c: bulk_str(c.cost_per_conversion), csv_to_field=lambda c, v: setattr(c, '_cost_per_conversion', float(v) if v else None)) ] @staticmethod def read_from_row_values_or_null(row_values): performance_data = PerformanceData() performance_data.read_from_row_values(row_values) return performance_data if performance_data.has_any_values else None @staticmethod def write_to_row_values_if_not_null(performance_data, row_values): if performance_data is not None: performance_data.write_to_row_values(row_values, False) def read_from_row_values(self, row_values): row_values.convert_to_entity(self, PerformanceData._MAPPINGS) def write_to_row_values(self, row_values, exclude_readonly_data): self.convert_to_values(row_values, PerformanceData._MAPPINGS) @property def has_any_values(self): return \ self.average_cost_per_click \ or self.average_cost_per_thousand_impressions \ or self.average_position \ or self.click_through_rate \ or self.clicks \ or self.conversions \ or self.cost_per_conversion \ or self.impressions \ or self.spend def write_to_stream(self, row_writer, exclude_readonly_data): pass def read_related_data_from_stream(self, stream_reader): super(PerformanceData, 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(PerformanceData, self).can_enclose_in_multiline_entity()
class BulkAppAdExtension(_BulkAdExtensionBase): """ Represents a app ad extension. This class exposes the :attr:`app_ad_extension` property that can be read and written as fields of the App Ad Extension record in a bulk file. For more information, see App 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, _AppAdExtension): raise ValueError( 'The type of ad_extension is: {0}, should be: {1}'.format( type(ad_extension), 'AppAdExtension')) super(BulkAppAdExtension, self).__init__(account_id=account_id, ad_extension=ad_extension) @property def app_ad_extension(self): """ The app ad extension. see App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. """ return self._ad_extension @app_ad_extension.setter def app_ad_extension(self, value): self._ad_extension = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.AppPlatform, field_to_csv=lambda c: c.app_ad_extension.AppPlatform, csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'AppPlatform', v)), _SimpleBulkMapping( header=_StringTable.AppStoreId, field_to_csv=lambda c: c.app_ad_extension.AppStoreId, csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'AppStoreId', v)), _SimpleBulkMapping( header=_StringTable.DestinationUrl, field_to_csv=lambda c: c.app_ad_extension.DestinationUrl, csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DestinationUrl', v)), _SimpleBulkMapping( header=_StringTable.Text, field_to_csv=lambda c: c.app_ad_extension.DisplayText, csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DisplayText', v)), _SimpleBulkMapping(header=_StringTable.DevicePreference, field_to_csv=lambda c: bulk_device_preference_str( c.app_ad_extension.DevicePreference), csv_to_field=lambda c, v: setattr( c.app_ad_extension, 'DevicePreference', parse_device_preference(v))), ] def process_mappings_from_row_values(self, row_values): self.app_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V11.create( 'AppAdExtension') self.app_ad_extension.Type = 'AppAdExtension' super(BulkAppAdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkAppAdExtension._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.app_ad_extension, 'app_ad_extension') super(BulkAppAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkAppAdExtension._MAPPINGS)