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 http://go.microsoft.com/fwlink/?LinkID=620264. *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: http://go.microsoft.com/fwlink/?LinkID=620264. """ 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_V10.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 http://go.microsoft.com/fwlink/?LinkID=730543. *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 http://go.microsoft.com/fwlink/?LinkID=730543. """ 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_V10.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 BulkTextAd(_BulkAd): """ Represents a Text Ad. This class exposes the :attr:`text_ad` property that can be read and written as fields of the Text Ad record in a bulk file. For more information, see Text Ad at http://go.microsoft.com/fwlink/?LinkID=620263. *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(BulkTextAd, self).__init__( ad_group_id, campaign_name, ad_group_name, ad, ) self.text_ad = ad @property def text_ad(self): """ The text ad. see Text Ad at http://go.microsoft.com/fwlink/?LinkID=620263. """ return self._ad @text_ad.setter def text_ad(self, text_ad): if text_ad is not None and not isinstance(text_ad, TextAd): raise ValueError('Not an instance of TextAd') self._ad = text_ad _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Title, field_to_csv=lambda c: c.text_ad.Title, csv_to_field=lambda c, v: setattr(c.text_ad, 'Title', v)), _SimpleBulkMapping( header=_StringTable.Text, field_to_csv=lambda c: c.text_ad.Text, csv_to_field=lambda c, v: setattr(c.text_ad, 'Text', v)), _SimpleBulkMapping( header=_StringTable.DisplayUrl, field_to_csv=lambda c: bulk_optional_str(c.text_ad.DisplayUrl), csv_to_field=lambda c, v: setattr(c.text_ad, 'DisplayUrl', v if v else '')), _SimpleBulkMapping( header=_StringTable.DestinationUrl, field_to_csv=lambda c: bulk_optional_str(c.text_ad.DestinationUrl), csv_to_field=lambda c, v: setattr(c.text_ad, 'DestinationUrl', v if v else '')), _SimpleBulkMapping( header=_StringTable.AdFormatPreference, field_to_csv=lambda c: field_to_csv_AdFormatPreference(c.text_ad), csv_to_field=lambda c, v: csv_to_field_AdFormatPreference( c.text_ad, v)), ] def process_mappings_from_row_values(self, row_values): self.text_ad = _CAMPAIGN_OBJECT_FACTORY_V10.create('TextAd') self.text_ad.Type = 'Text' super(BulkTextAd, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkTextAd._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.text_ad, 'text_ad') super(BulkTextAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkTextAd._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 _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 _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))), ] 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 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 http://go.microsoft.com/fwlink/?LinkId=618643. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, campaign_name=None, status=None, campaign_criterion=None): super(BulkCampaignProductScope, self).__init__() self._campaign_name = campaign_name self._status = status self._campaign_criterion = campaign_criterion @classmethod def _add_product_condition_to_row_values(cls, entity, value): criterion = entity.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.campaign_criterion.Id), csv_to_field=lambda c, v: setattr(c.campaign_criterion, 'Id', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.ParentId, field_to_csv=lambda c: bulk_str(c.campaign_criterion.CampaignId), csv_to_field=lambda c, v: setattr(c.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.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 campaign_criterion(self): """ Defines a Campaign Criterion """ return self._campaign_criterion @campaign_criterion.setter def campaign_criterion(self, campaign_criterion): self._campaign_criterion = campaign_criterion def process_mappings_from_row_values(self, row_values): self._campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'CampaignCriterion') self._campaign_criterion.Type = 'CampaignCriterion' self._campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ProductScope') self._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.campaign_criterion, '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 _BulkNegativeSite(_SingleRecordBulkEntity): """ This abstract base class for the bulk negative sites that are assigned individually to a campaign or ad group entity. *See also:* * :class:`.BulkAdGroupNegativeSite` * :class:`.BulkCampaignNegativeSite` """ def __init__(self, identifier, website=None): super(_BulkNegativeSite, self).__init__() self._identifier = identifier self._website = website @property def website(self): """ The URL of a website on which you do not want your ads displayed. Corresponds to the 'Website' field in the bulk file. :rtype: str """ return self._website @website.setter def website(self, website): self._website = website @property def status(self): """ The status of the negative site association. :rtype: str """ return self._identifier.status @status.setter def status(self, value): self._identifier.status = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Website, field_to_csv=lambda c: c.website, csv_to_field=lambda c, v: setattr(c, 'website', v) ), ] def process_mappings_from_row_values(self, row_values): self._identifier.read_from_row_values(row_values) row_values.convert_to_entity(self, _BulkNegativeSite._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._identifier.write_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, _BulkNegativeSite._MAPPINGS) @property def can_enclose_in_multiline_entity(self): return True def enclose_in_multiline_entity(self): return self.create_negative_sites_with_this_negative_site() def create_negative_sites_with_this_negative_site(self): raise NotImplementedError() def read_additional_data(self, stream_reader): super(_BulkNegativeSite, self).read_additional_data(stream_reader)
class _SingleRecordBulkEntity(with_metaclass(ABCMeta, BulkEntity)): def __init__(self): self._client_id = None self._last_modified_time = None self._errors = None @property def client_id(self): return self._client_id @client_id.setter def client_id(self, client_id): self._client_id = client_id @property def last_modified_time(self): return self._last_modified_time @property def errors(self): """ A list of :class:`BulkError` details in a separate bulk record that corresponds to the record of a :class:`.BulkEntity` derived instance. :rtype: list[BulkError] or None """ return self._errors @property def has_errors(self): return True if self.errors is not None and self.errors else False _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.ClientId, field_to_csv=lambda c: c.client_id, csv_to_field=lambda c, v: setattr(c, '_client_id', v), ), _SimpleBulkMapping( header=_StringTable.LastModifiedTime, field_to_csv=lambda c: bulk_datetime_str(c.last_modified_time), csv_to_field=lambda c, v: setattr(c, '_last_modified_time', parse_datetime(v) if v else None), ), ] def read_from_row_values(self, row_values): row_values.convert_to_entity(self, _SingleRecordBulkEntity._MAPPINGS) self.process_mappings_from_row_values(row_values) def write_to_row_values(self, row_values, exclude_readonly_data): self.convert_to_values(row_values, _SingleRecordBulkEntity._MAPPINGS) self.process_mappings_to_row_values(row_values, exclude_readonly_data) def read_related_data_from_stream(self, stream_reader): self.read_additional_data(stream_reader) self._read_errors(stream_reader) def write_to_stream(self, row_writer, exclude_readonly_data): row_writer.write_object_row(self, exclude_readonly_data) if not exclude_readonly_data: self._write_errors(row_writer) self.write_additional_data(row_writer) def _write_errors(self, row_writer): if self.has_errors: for error in self.errors: row_writer.write_object_row(error) def write_additional_data(self, row_writer): pass @abstractmethod def process_mappings_to_row_values(self, row_values, exclude_readonly_data): """ Process specific entity mappings to CSV values. Must be implemented by each entity. :param row_values: Row values. :type row_values: _RowValues :param exclude_readonly_data: excludeReadonlyData indicates whether readonly data should be written (such as errors, performance data etc.) :type exclude_readonly_data: bool """ raise NotImplementedError() @abstractmethod def process_mappings_from_row_values(self, row_values): """ Process specific entity mappings from CSV values. Must be implemented by each entity. :param row_values: :type row_values: _RowValues """ raise NotImplementedError() @abstractmethod def read_additional_data(self, stream_reader): pass def _read_errors(self, stream_reader): errors = [] success, error = stream_reader.try_read(BulkError) while success: error.entity = self errors.append(error) success, error = stream_reader.try_read(BulkError) self._errors = errors def enclose_in_multiline_entity(self): return super(_SingleRecordBulkEntity, self).enclose_in_multiline_entity() @property def can_enclose_in_multiline_entity(self): return super(_SingleRecordBulkEntity, self).can_enclose_in_multiline_entity
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 http://go.microsoft.com/fwlink/?LinkID=620269. """ 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 _BulkAdGroupNegativeSitesIdentifier(_BulkNegativeSiteIdentifier): def __init__(self, status=None, ad_group_id=None, ad_group_name=None, campaign_name=None): super(_BulkAdGroupNegativeSitesIdentifier, self).__init__( status, ad_group_id, ad_group_name, ) self._campaign_name = campaign_name def __eq__(self, other): is_name_not_empty = ( self.campaign_name is not None and len(self.campaign_name) > 0 and self.ad_group_name is not None and len(self.ad_group_name) > 0 ) return ( type(self) == type(other) and ( self.ad_group_id == other.ad_group_id or ( is_name_not_empty and self.campaign_name == other.campaign_name and self.ad_group_name == other.ad_group_name ) ) ) @property def ad_group_id(self): return self._entity_id @ad_group_id.setter def ad_group_id(self, value): self._entity_id = value @property def ad_group_name(self): return self._entity_name @ad_group_name.setter def ad_group_name(self, value): self._entity_name = value @property def campaign_name(self): return self._campaign_name @campaign_name.setter def campaign_name(self, campaign_name): self._campaign_name = campaign_name _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Campaign, field_to_csv=lambda c: c.campaign_name, csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) ), ] def read_from_row_values(self, row_values): super(_BulkAdGroupNegativeSitesIdentifier, self).read_from_row_values(row_values) row_values.convert_to_entity(self, _BulkAdGroupNegativeSitesIdentifier._MAPPINGS) def write_to_row_values(self, row_values, exclude_readonly_data): super(_BulkAdGroupNegativeSitesIdentifier, self).write_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, _BulkAdGroupNegativeSitesIdentifier._MAPPINGS) def _create_entity_with_this_identifier(self): return BulkAdGroupNegativeSites(identifier=self) @property def _parent_column_name(self): return _StringTable.AdGroup
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 http://go.microsoft.com/fwlink/?LinkID=620265. *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://msdn.microsoft.com/en-US/library/bing-ads-campaign-management-keyword.aspx """ 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)), _SimpleBulkMapping( header=_StringTable.BidStrategyType, field_to_csv=lambda c: field_to_csv_BidStrategyType(c.keyword), csv_to_field=lambda c, v: csv_to_field_BidStrategyType( c.keyword, v)), ] def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self._keyword, 'keyword') self.convert_to_values(row_values, BulkKeyword._MAPPINGS) if not exclude_readonly_data: QualityScoreData.write_to_row_values_if_not_null( self.quality_score_data, row_values) 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_V10.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 BulkError(_BulkObject): """ Contains bulk file error details in a separate record that corresponds to the record of a :class:`.BulkEntity` derived instance. Properties of this class and of classes that it is derived from, correspond to error fields of the 'Error' records in a bulk file. For more information, see Bulk File Schema at http://go.microsoft.com/fwlink/?LinkID=620269. *Example:* If you upload a :class:`.BulkCampaign` without setting the campaign name using :meth:`BulkServiceManager.upload_entities, and if you request errors to be returned in the results using the corresponding :attr:`SubmitUploadParameters.response_mode`, then the upload result file will contain a record that can be read with a :class:`.BulkFileReader` as an instance of :class:`.BulkError`. """ def __init__(self): self._error = None self._number = None self._editorial_location = None self._editorial_term = None self._editorial_reason_code = None self._publisher_countries = None self._entity = None self._field_path = None @property def entity(self): return self._entity @entity.setter def entity(self, value): self._entity = value @property def error(self): """ The error code, for example 'CampaignServiceEditorialValidationError'. Corresponds to the 'Error' field in the bulk file. For more information, see Bing Ads Operation Error Codes at http://go.microsoft.com/fwlink/?LinkId=511884. :rtype: str """ return self._error @property def number(self): """ The error number, for example '1042'. Corresponds to the 'Error Number' field in the bulk file. For more information, see Bing Ads Operation Error Codes at http://go.microsoft.com/fwlink/?LinkId=511884. :rtype: int """ return self._number @property def editorial_location(self): """ The location of the entity property that resulted in the editorial error, for example 'AdDescription'. Corresponds to the 'Editorial Location' field in the bulk file. :rtype: str """ return self._editorial_location @property def editorial_term(self): """ The term that resulted in the editorial error, for example 'bing'. Corresponds to the 'Editorial Term' field in the bulk file. :rtype: str """ return self._editorial_term @property def editorial_reason_code(self): """ The term that resulted in the editorial error, for example '17'. Corresponds to the 'Editorial Reason Code' field in the bulk file. For more information, see Bing Ads Editorial Failure Reason Codes at http://go.microsoft.com/fwlink/?LinkId=511883. :rtype: int """ return self._editorial_reason_code @property def field_path(self): """ The term that resulted in the editorial error. Corresponds to the 'Field Path' field in the bulk file. :rtype: int """ return self._field_path @property def publisher_countries(self): """ The publisher countries where editorial restriction is enforced, for example 'US'. Corresponds to the 'Publisher Countries' field in the bulk file. *Remarks:* In a bulk file, the list of publisher countries are delimited with a semicolon (;). :rtype: str """ return self._publisher_countries _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Error, field_to_csv=lambda c: bulk_str(c.error), csv_to_field=lambda c, v: setattr(c, '_error', v if v else None)), _SimpleBulkMapping( header=_StringTable.ErrorNumber, field_to_csv=lambda c: bulk_str(c.number), csv_to_field=lambda c, v: setattr(c, '_number', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.EditorialLocation, field_to_csv=lambda c: bulk_str(c.editorial_location), csv_to_field=lambda c, v: setattr(c, '_editorial_location', v if v else None)), _SimpleBulkMapping( header=_StringTable.EditorialReasonCode, field_to_csv=lambda c: bulk_str(c.editorial_reason_code), csv_to_field=lambda c, v: setattr(c, '_editorial_reason_code', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.EditorialTerm, field_to_csv=lambda c: bulk_str(c.editorial_term), csv_to_field=lambda c, v: setattr(c, '_editorial_term', v if v else None)), _SimpleBulkMapping( header=_StringTable.PublisherCountries, field_to_csv=lambda c: bulk_str(c.publisher_countries), csv_to_field=lambda c, v: setattr(c, '_publisher_countries', v if v else None)), _SimpleBulkMapping( header=_StringTable.FieldPath, field_to_csv=lambda c: bulk_str(c.field_path), csv_to_field=lambda c, v: setattr(c, '_field_path', v if v else None)), ] def can_enclose_in_multiline_entity(self): return super(BulkError, self).can_enclose_in_multiline_entity() def enclose_in_multiline_entity(self): return super(BulkError, self).enclose_in_multiline_entity() def read_from_row_values(self, row_values): row_values.convert_to_entity(self, BulkError._MAPPINGS) def read_related_data_from_stream(self, stream_reader): return super(BulkError, self).read_related_data_from_stream(stream_reader) def write_to_row_values(self, row_values, exclude_readonly_data): self.entity.write_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkError._MAPPINGS) def write_to_stream(self, stream_writer, exclude_readonly_data): return super(BulkError, self).write_to_stream(stream_writer, exclude_readonly_data)
class BulkCallAdExtension(_BulkAdExtensionBase): """ Represents a call ad extension. This class exposes the :attr:`call_ad_extension` property that can be read and written as fields of the Call Ad Extension record in a bulk file. For more information, see Call Ad Extension at http://go.microsoft.com/fwlink/?LinkID=620234. *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, _CallAdExtension): raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( type(ad_extension), 'CallAdExtension' )) super(BulkCallAdExtension, self).__init__( account_id=account_id, ad_extension=ad_extension ) @property def call_ad_extension(self): """ The call ad extension. see Call Ad Extension at http://go.microsoft.com/fwlink/?LinkID=620234. """ return self._ad_extension @call_ad_extension.setter def call_ad_extension(self, value): self._ad_extension = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.PhoneNumber, field_to_csv=lambda c: c.call_ad_extension.PhoneNumber, csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'PhoneNumber', v) ), _SimpleBulkMapping( header=_StringTable.CountryCode, field_to_csv=lambda c: c.call_ad_extension.CountryCode, csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'CountryCode', v) ), _SimpleBulkMapping( header=_StringTable.IsCallOnly, field_to_csv=lambda c: bulk_str(c.call_ad_extension.IsCallOnly), csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'IsCallOnly', v.lower() == 'true' if v else None) ), _SimpleBulkMapping( header=_StringTable.IsCallTrackingEnabled, field_to_csv=lambda c: bulk_str(c.call_ad_extension.IsCallTrackingEnabled), csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'IsCallTrackingEnabled', v.lower() == 'true' if v else None) ), _SimpleBulkMapping( header=_StringTable.RequireTollFreeTrackingNumber, field_to_csv=lambda c: bulk_str(c.call_ad_extension.RequireTollFreeTrackingNumber), csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'RequireTollFreeTrackingNumber', v.lower() == 'true' if v else None) ), ] def process_mappings_from_row_values(self, row_values): self.call_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V10.create('CallAdExtension') self.call_ad_extension.Type = 'CallAdExtension' super(BulkCallAdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkCallAdExtension._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.call_ad_extension, 'call_ad_extension') super(BulkCallAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkCallAdExtension._MAPPINGS)
class BulkLocationAdExtension(_BulkAdExtensionBase): """ Represents an location ad extension. This class exposes the :attr:`location_ad_extension` property that can be read and written as fields of the Location Ad Extension record in a bulk file. For more information, see Location Ad Extension at http://go.microsoft.com/fwlink/?LinkID=620235. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, account_id=None, ad_extension=None): if ad_extension and not isinstance(ad_extension, _LocationAdExtension): raise ValueError( 'The type of ad_extension is: {0}, should be: {1}'.format( type(ad_extension), 'LocationAdExtension')) super(BulkLocationAdExtension, self).__init__(account_id=account_id, ad_extension=ad_extension) @property def location_ad_extension(self): """ The location ad extension. see Location Ad Extension at http://go.microsoft.com/fwlink/?LinkID=620235. """ return self._ad_extension @location_ad_extension.setter def location_ad_extension(self, value): self._ad_extension = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.BusinessName, field_to_csv=lambda c: c.location_ad_extension.CompanyName, csv_to_field=lambda c, v: setattr(c.location_ad_extension, 'CompanyName', v)), _SimpleBulkMapping(header=_StringTable.PhoneNumber, field_to_csv=lambda c: bulk_optional_str( c.location_ad_extension.PhoneNumber), csv_to_field=lambda c, v: setattr( c.location_ad_extension, 'PhoneNumber', v if v else '')), _SimpleBulkMapping(header=_StringTable.GeoCodeStatus, field_to_csv=lambda c: bulk_str( c.location_ad_extension.GeoCodeStatus), csv_to_field=lambda c, v: setattr( c.location_ad_extension, 'GeoCodeStatus', v if v else None)), _SimpleBulkMapping(header=_StringTable.IconMediaId, field_to_csv=lambda c: bulk_str( c.location_ad_extension.IconMediaId), csv_to_field=lambda c, v: setattr( c.location_ad_extension, 'IconMediaId', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.AddressLine1, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.StreetAddress), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'StreetAddress', v))), _SimpleBulkMapping( header=_StringTable.AddressLine2, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: bulk_optional_str(x.StreetAddress2)), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'StreetAddress2', v if v else ''))), _SimpleBulkMapping( header=_StringTable.City, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.CityName), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'CityName', v))), _SimpleBulkMapping( header=_StringTable.ProvinceName, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.ProvinceName), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'ProvinceName', v))), _SimpleBulkMapping( header=_StringTable.StateOrProvince, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.ProvinceCode), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'ProvinceCode', v))), _SimpleBulkMapping( header=_StringTable.PostalCode, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.PostalCode), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'PostalCode', v))), _SimpleBulkMapping( header=_StringTable.CountryCode, field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( c, lambda x: x.CountryCode), csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( c, lambda x: setattr(x, 'CountryCode', v))), _SimpleBulkMapping( header=_StringTable.Latitude, field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part( c, lambda x: bulk_str( float(x.LatitudeInMicroDegrees) / 1000000.0) if x.LatitudeInMicroDegrees is not None else None), csv_to_field=lambda c, v: BulkLocationAdExtension. set_geo_point_part( c, lambda x, latitude: setattr( x, 'LatitudeInMicroDegrees', int(round(float(latitude) * 1000000))), v)), _SimpleBulkMapping( header=_StringTable.Longitude, field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part( c, lambda x: bulk_str( float(x.LongitudeInMicroDegrees) / 1000000.0) if x.LongitudeInMicroDegrees is not None else None), csv_to_field=lambda c, v: BulkLocationAdExtension. set_geo_point_part( c, lambda x, longitude: setattr( x, 'LongitudeInMicroDegrees', int(round(float(longitude) * 1000000))), v)), ] @staticmethod def get_address_part(bulk_ad_extension, get_func): if bulk_ad_extension.location_ad_extension.Address is not None: return get_func(bulk_ad_extension.location_ad_extension.Address) else: return None @staticmethod def set_address_part(bulk_ad_extension, set_func): if bulk_ad_extension.location_ad_extension.Address is None: bulk_ad_extension.location_ad_extension.Address = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'Address') set_func(bulk_ad_extension.location_ad_extension.Address) @staticmethod def get_geo_point_part(bulk_ad_extension, get_func): if bulk_ad_extension.location_ad_extension.GeoPoint is not None: return get_func(bulk_ad_extension.location_ad_extension.GeoPoint) else: return None @staticmethod def set_geo_point_part(bulk_ad_extension, set_func, value): if not value: return if bulk_ad_extension.location_ad_extension.GeoPoint is None: bulk_ad_extension.location_ad_extension.GeoPoint = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'GeoPoint') set_func(bulk_ad_extension.location_ad_extension.GeoPoint, value) def process_mappings_from_row_values(self, row_values): self.location_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'LocationAdExtension') self.location_ad_extension.Type = 'LocationAdExtension' if row_values[_StringTable.Latitude] or row_values[ _StringTable.Longitude]: self.location_ad_extension.GeoPoint = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'GeoPoint') super(BulkLocationAdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkLocationAdExtension._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.location_ad_extension, 'location_ad_extension') super(BulkLocationAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) self.convert_to_values(row_values, BulkLocationAdExtension._MAPPINGS)
class 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 http://go.microsoft.com/fwlink/?LinkID=620277. *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 http://go.microsoft.com/fwlink/?LinkID=620277. """ 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_V10.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 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 http://go.microsoft.com/fwlink/?LinkID=730549. *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 http://go.microsoft.com/fwlink/?LinkID=730549. """ 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_V10.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 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 http://go.microsoft.com/fwlink/?LinkID=620252. *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 http://go.microsoft.com/fwlink/?LinkID=620252. """ 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: c.ad_group.Language, csv_to_field=lambda c, v: setattr(c.ad_group, 'Language', v) ), _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_V10.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 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_V10.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 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 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 http://go.microsoft.com/fwlink/?LinkID=620269. """ 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 _BulkAdExtensionAssociation(_SingleRecordBulkEntity): """ This class provides properties that are shared by all bulk ad extension association classes. For more information, see Bulk File Schema at http://go.microsoft.com/fwlink/?LinkID=620269. """ 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 http://go.microsoft.com/fwlink/?LinkId=620284. 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_V10.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 BulkBudget(_SingleRecordBulkEntity): """ Represents a budget 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 Budget record in a bulk file. For more information, see Budget at http://go.microsoft.com/fwlink/?LinkID=799348 *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, budget=None, status=None, account_id=None): super(BulkBudget, self).__init__() self._budget = budget self._status = status self._account_id = account_id @property def budget(self): """ the Budget object, see more detail at: http://go.microsoft.com/fwlink/?LinkID=799348 """ return self._budget @budget.setter def budget(self, value): self._budget = value @property def status(self): """ the status of bulk record Corresponds to the 'Status' field in the bulk file. :rtype: str """ return self._status @status.setter def status(self, value): self._status = value @property def account_id(self): """ the id of the account which contains the budget Corresponds to the 'Parent Id' field in the bulk file. :rtype: long """ return self._account_id @account_id.setter def account_id(self, value): self._account_id = value _MAPPINGS = [ _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.budget.Id), csv_to_field=lambda c, v: setattr(c.budget, 'Id', long(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', long(v) if v else None)), _SimpleBulkMapping(header=_StringTable.Status, field_to_csv=lambda c: c.status, csv_to_field=lambda c, v: setattr(c, 'status', v)), _SimpleBulkMapping( header=_StringTable.BudgetName, field_to_csv=lambda c: bulk_str(c.budget.Name), csv_to_field=lambda c, v: setattr(c.budget, 'Name', v)), _SimpleBulkMapping( header=_StringTable.BudgetType, field_to_csv=lambda c: bulk_str(c.budget.BudgetType), csv_to_field=lambda c, v: csv_to_field_BudgetType(c.budget, v)), _SimpleBulkMapping( header=_StringTable.Budget, field_to_csv=lambda c: bulk_str(c.budget.Amount), csv_to_field=lambda c, v: setattr(c.budget, 'Amount', Decimal(v) if v else None)), ] def process_mappings_from_row_values(self, row_values): self._budget = _CAMPAIGN_OBJECT_FACTORY_V10.create('Budget') row_values.convert_to_entity(self, BulkBudget._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.budget, 'budget') self.convert_to_values(row_values, BulkBudget._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkBudget, 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 http://go.microsoft.com/fwlink/?LinkID=620233. *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 BulkAdGroupRemarketingListAssociation(_SingleRecordBulkEntity): """ Represents an Ad Group Remarketing List Association that can be read or written in a bulk file. This class exposes the :attr:`ad_group_remarketing_list_association` property that can be read and written as fields of the Ad Group Remarketing List Association record in a bulk file. For more information, see Ad Group Remarketing List Association at http://go.microsoft.com/fwlink/?LinkId=799353. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, ad_group_remarketing_list_association=None, campaign_name=None, ad_group_name=None, remarketing_list_name=None): super(BulkAdGroupRemarketingListAssociation, self).__init__() self._ad_group_remarketing_list_association = ad_group_remarketing_list_association 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.ad_group_remarketing_list_association.Status), csv_to_field=lambda c, v: setattr(c.ad_group_remarketing_list_association, 'Status', v if v else None) ), _SimpleBulkMapping( _StringTable.Id, field_to_csv=lambda c: bulk_str(c.ad_group_remarketing_list_association.Id), csv_to_field=lambda c, v: setattr(c.ad_group_remarketing_list_association, 'Id', int(v) if v else None) ), _SimpleBulkMapping( _StringTable.ParentId, field_to_csv=lambda c: bulk_str(c.ad_group_remarketing_list_association.AdGroupId), csv_to_field=lambda c, v: setattr(c.ad_group_remarketing_list_association, '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.RemarketingList, field_to_csv=lambda c: c.remarketing_list_name, csv_to_field=lambda c, v: setattr(c, 'remarketing_list_name', v) ), _SimpleBulkMapping( _StringTable.BidAdjustment, field_to_csv=lambda c: bulk_str(c.ad_group_remarketing_list_association.BidAdjustment), csv_to_field=lambda c, v: setattr(c.ad_group_remarketing_list_association, 'BidAdjustment', float(v) if v else None) ), _SimpleBulkMapping( _StringTable.RemarketingListId, field_to_csv=lambda c: bulk_str(c.ad_group_remarketing_list_association.RemarketingListId), csv_to_field=lambda c, v: setattr(c.ad_group_remarketing_list_association, 'RemarketingListId', int(v) if v else None) ), ] @property def ad_group_remarketing_list_association(self): """ Defines an Ad Group Remarketing List Association """ return self._ad_group_remarketing_list_association @ad_group_remarketing_list_association.setter def ad_group_remarketing_list_association(self, ad_group_remarketing_list_association): self._ad_group_remarketing_list_association = ad_group_remarketing_list_association @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_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.ad_group_remarketing_list_association, 'ad_group_remarketing_list_association') self.convert_to_values(row_values, BulkAdGroupRemarketingListAssociation._MAPPINGS) def process_mappings_from_row_values(self, row_values): self._ad_group_remarketing_list_association = _CAMPAIGN_OBJECT_FACTORY_V10.create('AdGroupRemarketingListAssociation') row_values.convert_to_entity(self, BulkAdGroupRemarketingListAssociation._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkAdGroupRemarketingListAssociation, 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 http://go.microsoft.com/fwlink/?LinkID=620239. *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://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-campaign.aspx """ 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': c.campaign.Settings = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ArrayOfSetting') shopping_setting = _CAMPAIGN_OBJECT_FACTORY_V10.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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: 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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: 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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: 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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: 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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: 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 if 'shopping' in [ campaign_type.lower() for campaign_type in c.campaign.CampaignType ]: shopping_setting = c._get_shopping_setting() if not shopping_setting: return None shopping_setting.SalesCountryCode = v _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))), _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)), _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( # TODO now use bulk_str not bulk_optional_str 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)), _SimpleBulkMapping( header=_StringTable.BidStrategyType, field_to_csv=lambda c: field_to_csv_BidStrategyType(c.campaign), csv_to_field=lambda c, v: csv_to_field_BidStrategyType( c.campaign, v)), _SimpleBulkMapping( header=_StringTable.BudgetId, field_to_csv=lambda c: bulk_str(c.campaign.BudgetId), csv_to_field=lambda c, v: setattr(c.campaign, 'BudgetId', long(v) if v else None)), _SimpleBulkMapping( header=_StringTable.BudgetType, field_to_csv=lambda c: bulk_str(c.campaign.BudgetType), csv_to_field=lambda c, v: csv_to_field_BudgetType(c.campaign, v)), _SimpleBulkMapping( header=_StringTable.BudgetName, field_to_csv=lambda c: bulk_str(c.budget_name), csv_to_field=lambda c, v: setattr(c, 'budget_name', v if v else None)), ] 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_V10.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 BulkAdGroupNegativeDynamicSearchAdTarget(_SingleRecordBulkEntity): """ Represents a Ad Group Criterion that can be read or written in a bulk file. This class exposes the :attr:`ad_group_criterion` property that can be read and written as fields of the Ad Group Negative Dynamic Search Ad Target record in a bulk file. For more information, see Ad Group Negative Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836838. *See also:* * :class:`.BulkServiceManager` * :class:`.BulkOperation` * :class:`.BulkFileReader` * :class:`.BulkFileWriter` """ def __init__(self, campaign_name=None, ad_group_name=None, status=None, ad_group_criterion=None): super(BulkAdGroupNegativeDynamicSearchAdTarget, self).__init__() self._campaign_name = campaign_name self._ad_group_name = ad_group_name self._status = status self._ad_group_criterion = ad_group_criterion _MAPPINGS = [ _SimpleBulkMapping(header=_StringTable.Status, field_to_csv=lambda c: c.status, csv_to_field=lambda c, v: setattr(c, 'status', v)), _SimpleBulkMapping( header=_StringTable.Id, field_to_csv=lambda c: bulk_str(c.ad_group_criterion.Id), csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Id', int(v) if v else None)), _SimpleBulkMapping( header=_StringTable.ParentId, field_to_csv=lambda c: bulk_str(c.ad_group_criterion.AdGroupId), csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'AdGroupId', int(v) if v else None)), _SimpleBulkMapping( 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.Name, field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName( c.ad_group_criterion), csv_to_field=lambda c, v: csv_to_field_WebpageParameter_CriterionName( c.ad_group_criterion, v)), _ComplexBulkMapping( entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter( c.ad_group_criterion, v), csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter( v, c.ad_group_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 @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 ad_group_criterion(self): """ Defines a Ad Group Criterion """ return self._ad_group_criterion @ad_group_criterion.setter def ad_group_criterion(self, ad_group_criterion): self._ad_group_criterion = ad_group_criterion def process_mappings_from_row_values(self, row_values): self._ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'NegativeAdGroupCriterion') self._ad_group_criterion.Type = 'NegativeAdGroupCriterion' self._ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:Webpage') self._ad_group_criterion.Criterion.Type = 'Webpage' row_values.convert_to_entity( self, BulkAdGroupNegativeDynamicSearchAdTarget._MAPPINGS) def process_mappings_to_row_values(self, row_values, exclude_readonly_data): self._validate_property_not_null(self.ad_group_criterion, 'ad_group_criterion') self.convert_to_values( row_values, BulkAdGroupNegativeDynamicSearchAdTarget._MAPPINGS) def read_additional_data(self, stream_reader): super(BulkAdGroupNegativeDynamicSearchAdTarget, 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 http://go.microsoft.com/fwlink/?LinkId=799352. *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.RemarketingList, 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)), ] @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_V10.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)