def process_mappings_from_row_values(self, row_values): self._campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('NegativeCampaignCriterion') self._campaign_criterion.Type = 'NegativeCampaignCriterion' self._campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:Webpage') self._campaign_criterion.Criterion.Type = 'Webpage' row_values.convert_to_entity(self, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS)
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 _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]
def process_mappings_from_row_values(self, row_values): self._ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('BiddableAdGroupCriterion') self._ad_group_criterion.Type = 'BiddableAdGroupCriterion' self._ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:Webpage') self._ad_group_criterion.Criterion.Type = 'Webpage' self._ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V10.create('FixedBid') self._ad_group_criterion.CriterionBid.Type = 'FixedBid' row_values.convert_to_entity(self, BulkAdGroupDynamicSearchAdTarget._MAPPINGS) self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)
def parse_keyword_bid(value): bid = _CAMPAIGN_OBJECT_FACTORY_V10.create('Bid') if not value: bid.Amount = None else: bid.Amount = float(value) return bid
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 csv_to_field_AdFormatPreference(entity, value): """ parse csv content and set entity attribute :param entity: entity which has ForwardCompatibilityMap attribute :param value: csv content value :return: """ ad_format_preference = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns2:KeyValuePairOfstringstring') ad_format_preference.key = 'NativePreference' if value is None or value == '' or value == 'All': ad_format_preference.value = 'False' elif value == 'Native': ad_format_preference.value = 'True' else: raise ValueError('Unknown value for Native Preference: {0}'.format(value)) entity.ForwardCompatibilityMap = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns2:ArrayOfKeyValuePairOfstringstring') entity.ForwardCompatibilityMap.KeyValuePairOfstringstring.append(ad_format_preference)
def _read_is_excluded(cls, entity, row_value): if row_value is None: row_value = '' row_value = row_value.lower() if row_value == 'yes' or row_value == 'true': is_excluded = True elif row_value == 'no' or row_value == 'false': is_excluded = False else: raise ValueError('IsExcluded can only be set to TRUE|FALSE in Ad Group Product Partition row') if is_excluded: product_partition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ProductPartition') product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ProductCondition') product_partition.Type = 'ProductPartition' negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('NegativeAdGroupCriterion') negative_ad_group_criterion.Criterion = product_partition negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' entity.ad_group_criterion = negative_ad_group_criterion else: product_partition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ProductPartition') product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ProductCondition') product_partition.Type = 'ProductPartition' fixed_bid = _CAMPAIGN_OBJECT_FACTORY_V10.create('FixedBid') fixed_bid.Type = 'FixedBid' biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create('BiddableAdGroupCriterion') biddable_ad_group_criterion.Criterion = product_partition biddable_ad_group_criterion.CriterionBid = fixed_bid biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' entity.ad_group_criterion = biddable_ad_group_criterion
def csv_to_field_WebpageParameter_CriterionName(entity, value): if value is None or value == '': return if entity.Criterion is not None and isinstance(entity.Criterion, type(Webpage)): entity.Criterion.Parameter.CriterionName = value else: webpage = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:Webpage') webpage.Parameter.CriterionName = value entity.Criterion = webpage
def parse_date(d_str): if not d_str: return None parsed_date = datetime.strptime(d_str, _BULK_DATE_FORMAT) bing_ads_date = _CAMPAIGN_OBJECT_FACTORY_V10.create('Date') bing_ads_date.Day = parsed_date.day bing_ads_date.Month = parsed_date.month bing_ads_date.Year = parsed_date.year return bing_ads_date
def parse_rule_groups(groups_str): group_split = ')) or ((' group_str_list = groups_str.split(group_split) rule_item_groups = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:ArrayOfRuleItemGroup') for group_str in group_str_list: item_group = parse_rule_items(group_str) rule_item_groups.RuleItemGroup.append(item_group) return rule_item_groups
def parse_rule_items(items_str): item_split = ') and (' item_str_list = items_str.split(item_split) rule_item_group = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:RuleItemGroup') for item_str in item_str_list: item = parse_string_rule_item(item_str) rule_item_group.Items.RuleItem.append(item) return rule_item_group
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 parse_rule_groups(groups_str): group_split = ')) or ((' group_str_list = groups_str.split(group_split) rule_item_groups = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:ArrayOfRuleItemGroup') for group_str in group_str_list: item_group = parse_rule_items(group_str) rule_item_groups.RuleItemGroup.append(item_group) return rule_item_groups
def parse_rule_PageVisitorsWhoDidNotVisitAnotherPage(rule_str): rule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:PageVisitorsWhoDidNotVisitAnotherPageRule') rule.Type = 'PageVisitorsWhoDidNotVisitAnotherPage' groups_split = '))) and not (((' groups_string_list = rule_str.split(groups_split) rule.IncludeRuleItemGroups = parse_rule_groups(groups_string_list[0]) rule.ExcludeRuleItemGroups = parse_rule_groups(groups_string_list[1]) return rule
def csv_to_field_AdFormatPreference(entity, value): """ parse csv content and set entity attribute :param entity: entity which has ForwardCompatibilityMap attribute :param value: csv content value :return: """ ad_format_preference = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns2:KeyValuePairOfstringstring') ad_format_preference.key = 'NativePreference' if value is None or value == '' or value == 'All': ad_format_preference.value = 'False' elif value == 'Native': ad_format_preference.value = 'True' else: raise ValueError( 'Unknown value for Native Preference: {0}'.format(value)) entity.ForwardCompatibilityMap = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns2:ArrayOfKeyValuePairOfstringstring') entity.ForwardCompatibilityMap.KeyValuePairOfstringstring.append( ad_format_preference)
def csv_to_entity_DSAWebpageParameter(row_values, entity): """ convert Campaign/Ad Group Criterion (WebpagePage) Web page parameters to bulk row values :param row_values: bulk row values :param entity: campaign/ad group criterion entity """ MAX_NUMBER_OF_CONDITIONS = 3 condition_prefix = _StringTable.DynamicAdTargetCondition1[:-1] value_prefix = _StringTable.DynamicAdTargetValue1[:-1] conditions = [] for i in range(0, MAX_NUMBER_OF_CONDITIONS): condition_success, webpage_condition = row_values.try_get_value(condition_prefix + str(i + 1)) value_success, webpage_value = row_values.try_get_value(value_prefix + str(i + 1)) if condition_success and value_success and webpage_condition is not None and webpage_condition != '': condition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:WebpageCondition') if webpage_condition.lower() == 'url': condition.Operand = WebpageConditionOperand.Url elif webpage_condition.lower() == "category": condition.Operand = WebpageConditionOperand.Category elif webpage_condition.lower() == 'pagetitle': condition.Operand = WebpageConditionOperand.PageTitle elif webpage_condition.lower() == 'pagecontent': condition.Operand = WebpageConditionOperand.PageContent else: # TODO wait bug 54825 to be fixed if webpage_condition.lower() == 'none': continue raise ValueError("Unknown WebpageConditionOperand value: {0}".format(webpage_condition)) condition.Argument = webpage_value conditions.append(condition) if len(conditions) > 0: if entity.Criterion is not None and isinstance(entity.Criterion, type(Webpage)): entity.Criterion.Parameter.Conditions.WebpageCondition = conditions else: webpage = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:Webpage') webpage.Parameter.Conditions.WebpageCondition = conditions entity.Criterion = webpage
def csv_to_field_BidStrategyType(entity, value): """ set BiddingScheme :param entity: entity which has BiddingScheme attribute :param value: the content in csv :return: """ if value is None or value == '': return elif value == 'EnhancedCpc': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:EnhancedCpcBiddingScheme') elif value == 'InheritFromParent': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:InheritFromParentBiddingScheme') elif value == 'MaxConversions': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:MaxConversionsBiddingScheme') elif value == 'ManualCpc': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:ManualCpcBiddingScheme') elif value == 'TargetCpa': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:TargetCpaBiddingScheme') elif value == 'MaxClicks': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ns0:MaxClicksBiddingScheme') else: raise ValueError('Unknown Bid Strategy Type') entity.BiddingScheme.Type = value
def parse_rule_CustomEvents(rule_str): rule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:CustomEventsRule') rule.Type = 'CustomEvents' item_split = ') and (' pattern_for_operand_str = '^(Category|Action|Label|Value) ([^()]*)$' pattern_for_operand = re.compile(pattern_for_operand_str) pattern_number_item_str = '^(Equals|GreaterThan|LessThan|GreaterThanEqualTo|LessThanEqualTo) ([^()]*)$' pattern_number_item = re.compile(pattern_number_item_str) pattern_string_item_str = '^(Equals|Contains|BeginsWith|EndsWith|NotEquals|DoesNotContain|DoesNotBeginWith|DoesNotEndWith) ([^()]*)$' pattern_string_item = re.compile(pattern_string_item_str) item_string_list = rule_str.split(item_split) for item_string in item_string_list: item_string = item_string.strip('(').strip(')') match_for_operand = pattern_for_operand.match(item_string) if not match_for_operand: raise ValueError('Invalid Custom Event rule item: {0}'.format(item_string)) operand = match_for_operand.group(1) operater_and_value_string = match_for_operand.group(2) if operand.lower() == 'value': match_number_item = pattern_number_item.match(operater_and_value_string) if not match_number_item: raise ValueError('Invalid Custom Event number rule item: {0}'.format(item_string)) rule.ValueOperator = parse_number_operator(match_number_item.group(1)) rule.Value = float(match_number_item.group(2)) else: match_string_item = pattern_string_item.match(operater_and_value_string) if not match_string_item: raise ValueError('Invalid Custom Event string rule item: {0}'.format(item_string)) if operand.lower() == 'category': rule.CategoryOperator = parse_string_operator(match_string_item.group(1)) rule.Category = match_string_item.group(2) elif operand.lower() == 'label': rule.LabelOperator = parse_string_operator(match_string_item.group(1)) rule.Label = match_string_item.group(2) elif operand.lower() == 'action': rule.ActionOperator = parse_string_operator(match_string_item.group(1)) rule.Action = match_string_item.group(2) else: raise ValueError('Invalid Custom Event string rule operator: {0}'.format(operand)) return rule
def csv_to_field_DSADomainLanguage(entity, value): """ Set Campaign settings Language from bulk value if the campaign type is Dynamic Search Campaign :param entity: campaign entity :param value: bulk str value """ if not entity.CampaignType or len(entity.CampaignType) == 0 or entity.CampaignType[0] != "DynamicSearchAds": return if len(entity.Settings.Setting) > 0 and entity.Settings.Setting[0].Type == 'DynamicSearchAdsSetting': entity.Settings.Setting[0].Language = value else: setting = _CAMPAIGN_OBJECT_FACTORY_V10.create('DynamicSearchAdsSetting') setting.Language = value setting.Type = 'DynamicSearchAdsSetting' entity.Settings.Setting.append(setting)
def format_Day(value): Day = _CAMPAIGN_OBJECT_FACTORY_V10.create('Day') if value.lower() == 'monday': return Day.Monday elif value.lower() == 'tuesday': return Day.Tuesday elif value.lower() == 'wednesday': return Day.Wednesday elif value.lower() == 'thursday': return Day.Thursday elif value.lower() == 'friday': return Day.Friday elif value.lower() == 'saturday': return Day.Saturday elif value.lower() == 'sunday': return Day.Sunday raise ValueError('Unable to parse day: {0}'.format(value))
def parse_string_rule_item(item_str): item_str = item_str.strip('(').strip(')') pattern_str = '^(Url|ReferrerUrl|None) (Equals|Contains|BeginsWith|EndsWith|NotEquals|DoesNotContain|DoesNotBeginWith|DoesNotEndWith) ([^()]*)$' pattern = re.compile(pattern_str) match = pattern.match(item_str) if not match: ValueError('Invalid Rule Item:{0}'.format(item_str)) item = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:StringRuleItem') item.Type = 'String' item.Operand = match.group(1) item.Operator = parse_string_operator(match.group(2)) item.Value = match.group(3) return item
def csv_to_field_UrlCustomParameters(entity, value): if value is None or value.strip() == '': return splitter = re.compile(custom_param_splitter) pattern = re.compile(custom_param_pattern) #params = _CAMPAIGN_OBJECT_FACTORY_V10.create("ns0:ArrayOfCustomParameter") params = [] param_strs = splitter.split(value) for param_str in param_strs: match = pattern.match(param_str) if match: custom_parameter = _CAMPAIGN_OBJECT_FACTORY_V10.create("ns0:CustomParameter") custom_parameter.Key = match.group(1) custom_parameter.Value = unescape_parameter_text(match.group(2)) params.append(custom_parameter) if len(params) > 0: entity.UrlCustomParameters.Parameters.CustomParameter = params
def __init__( self, account_id=None, site_links_ad_extension=None, bulk_site_link=None, identifier=None, ): super(BulkSiteLinkAdExtension, self).__init__() self._account_id = account_id self._site_links_ad_extension = site_links_ad_extension self._bulk_site_links = [] self._bulk_site_link = bulk_site_link self._identifier = identifier if self._bulk_site_link and self._identifier: raise ValueError( 'Conflicting arguments of bulk site link and site link identifier provided.' ) if self._bulk_site_link: if not isinstance(self._bulk_site_link, BulkSiteLink): raise ValueError( 'Site link object provided is not of type: {0}.'.format( BulkSiteLink.__name__)) self._identifier = self._bulk_site_link._identifier if self._identifier: if not isinstance(self._identifier, _SiteLinkAdExtensionIdentifier): raise ValueError( 'Site link identifier object provided is not of type: {0}.' .format(_SiteLinkAdExtensionIdentifier.__name__)) self._has_delete_all_row = self._identifier.is_delete_row self._site_links_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'SiteLinksAdExtension') self._site_links_ad_extension.Type = 'SiteLinksAdExtension' self._site_links_ad_extension.Id = self._identifier.ad_extension_id self._site_links_ad_extension.Status = self._identifier.status self._site_links_ad_extension.Version = self._identifier.version self.account_id = self._identifier.account_id if self._bulk_site_link: self._bulk_site_links.append(self._bulk_site_link)
def csv_to_field_AdSchedule(entity, value): if value is None or value.strip() == '': return daytime_strs = value.split(';') ad_schedule_pattern = '\((Monday|Tuesday|Wednesday|ThursDay|Friday|Saturday|Sunday)\[(\d\d?):(\d\d)-(\d\d?):(\d\d)\]\)' pattern = re.compile(ad_schedule_pattern, re.IGNORECASE) daytimes = [] for daytime_str in daytime_strs: match = pattern.match(daytime_str) if match: daytime = _CAMPAIGN_OBJECT_FACTORY_V10.create('DayTime') daytime.Day = format_Day(match.group(1)) daytime.StartHour = int(match.group(2)) daytime.StartMinute = parse_minute(match.group(3)) daytime.EndHour = int(match.group(4)) daytime.EndMinute = parse_minute(match.group(5)) daytimes.append(daytime) else: raise ValueError('Unable to parse DayTime: {0}'.format(daytime_str)) entity.DayTimeRanges.DayTime = daytimes
def _read_is_excluded(cls, entity, row_value): if row_value is None: row_value = '' row_value = row_value.lower() if row_value == 'yes' or row_value == 'true': is_excluded = True elif row_value == 'no' or row_value == 'false': is_excluded = False else: raise ValueError( 'IsExcluded can only be set to TRUE|FALSE in Ad Group Product Partition row' ) if is_excluded: product_partition = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ProductPartition') product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ProductCondition') product_partition.Type = 'ProductPartition' negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'NegativeAdGroupCriterion') negative_ad_group_criterion.Criterion = product_partition negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' entity.ad_group_criterion = negative_ad_group_criterion else: product_partition = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ProductPartition') product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'ProductCondition') product_partition.Type = 'ProductPartition' fixed_bid = _CAMPAIGN_OBJECT_FACTORY_V10.create('FixedBid') fixed_bid.Type = 'FixedBid' biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V10.create( 'BiddableAdGroupCriterion') biddable_ad_group_criterion.Criterion = product_partition biddable_ad_group_criterion.CriterionBid = fixed_bid biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' entity.ad_group_criterion = biddable_ad_group_criterion
def add_conditions_from_row_values(row_values, conditions): """ :param row_values: :type row_values: _RowValues :param conditions: :type conditions: list[ProductCondition] :rtype: None """ condition_header_prefix = _StringTable.ProductCondition1[:-1] value_header_prefix = _StringTable.ProductValue1[:-1] for i in range(1, _ProductConditionHelper.MAX_NUMBER_OF_CONDITIONS + 1): condition_success, product_condition = row_values.try_get_value(condition_header_prefix + str(i)) value_success, product_value = row_values.try_get_value(value_header_prefix + str(i)) if product_condition and product_value: condition = _CAMPAIGN_OBJECT_FACTORY_V10.create('ProductCondition') condition.Operand = product_condition condition.Attribute = product_value conditions.append(condition)
def __init__(self, account_id=None, site_links_ad_extension=None, bulk_site_link=None, identifier=None,): super(BulkSiteLinkAdExtension, self).__init__() self._account_id = account_id self._site_links_ad_extension = site_links_ad_extension self._bulk_site_links = [] self._bulk_site_link = bulk_site_link self._identifier = identifier if self._bulk_site_link and self._identifier: raise ValueError('Conflicting arguments of bulk site link and site link identifier provided.') if self._bulk_site_link: if not isinstance(self._bulk_site_link, BulkSiteLink): raise ValueError('Site link object provided is not of type: {0}.'.format(BulkSiteLink.__name__)) self._identifier = self._bulk_site_link._identifier if self._identifier: if not isinstance(self._identifier, _SiteLinkAdExtensionIdentifier): raise ValueError( 'Site link identifier object provided is not of type: {0}.'.format(_SiteLinkAdExtensionIdentifier.__name__) ) self._has_delete_all_row = self._identifier.is_delete_row self._site_links_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V10.create('SiteLinksAdExtension') self._site_links_ad_extension.Type = 'SiteLinksAdExtension' self._site_links_ad_extension.Id = self._identifier.ad_extension_id self._site_links_ad_extension.Status = self._identifier.status self._site_links_ad_extension.Version = self._identifier.version self.account_id = self._identifier.account_id if self._bulk_site_link: self._bulk_site_links.append(self._bulk_site_link)
def field_to_csv_BidStrategyType(entity): """ parse entity to csv content :param entity: entity which has BiddingScheme attribute :return: csv content """ if entity.BiddingScheme is None or type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:BiddingScheme')): return None elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:EnhancedCpcBiddingScheme')): return 'EnhancedCpc' elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:InheritFromParentBiddingScheme')): return 'InheritFromParent' elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:MaxConversionsBiddingScheme')): return 'MaxConversions' elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:ManualCpcBiddingScheme')): return 'ManualCpc' elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:TargetCpaBiddingScheme')): return 'TargetCpa' elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:MaxClicksBiddingScheme')): return 'MaxClicks' else: raise TypeError('Unsupported Bid Strategy Type')
def csv_to_field_BidStrategyType(entity, value): """ set BiddingScheme :param entity: entity which has BiddingScheme attribute :param value: the content in csv :return: """ if value is None or value == '': return elif value == 'EnhancedCpc': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:EnhancedCpcBiddingScheme') elif value == 'InheritFromParent': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:InheritFromParentBiddingScheme') elif value == 'MaxConversions': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:MaxConversionsBiddingScheme') elif value == 'ManualCpc': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:ManualCpcBiddingScheme') elif value == 'TargetCpa': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:TargetCpaBiddingScheme') elif value == 'MaxClicks': entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:MaxClicksBiddingScheme') else: raise ValueError('Unknown Bid Strategy Type') entity.BiddingScheme.Type = value
def parse_rule_PageVisitors(rule_str): rule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:PageVisitorsRule') rule.Type = 'PageVisitors' rule.RuleItemGroups = parse_rule_groups(rule_str) return rule
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 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)
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 set_data_from_identifier(self, identifier): self._campaign_negative_sites = _CAMPAIGN_OBJECT_FACTORY_V10.create('CampaignNegativeSites') self.campaign_negative_sites.CampaignId = identifier.campaign_id self._campaign_name = identifier.campaign_name
from bingads.internal.extensions import bulk_optional_str from bingads.v10.internal.bulk.mappings import _SimpleBulkMapping from bingads.v10.internal.bulk.string_table import _StringTable from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V10 from .common import * from .common import _BulkAdExtensionBase from .common import _BulkCampaignAdExtensionAssociation _LocationAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V10.create('LocationAdExtension')) 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):
from bingads.v10.internal.bulk.string_table import _StringTable from six import PY2 import re from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V10 DELETE_VALUE = "delete_value" _BULK_DATETIME_FORMAT = '%m/%d/%Y %H:%M:%S' _BULK_DATETIME_FORMAT_2 = '%m/%d/%Y %H:%M:%S.%f' _BULK_DATE_FORMAT = "%m/%d/%Y" url_splitter = ";\\s*(?=https?://)" custom_param_splitter = "(?<!\\\\);\\s*" custom_param_pattern = "^\\{_(.*?)\\}=(.*$)" BudgetLimitType = _CAMPAIGN_OBJECT_FACTORY_V10.create('BudgetLimitType') def bulk_str(value): if value is None or (hasattr(value, 'value') and value.value is None): return None if isinstance(value, str): return value if PY2: if isinstance(value, unicode): return value return str(value) def bulk_upper_str(value): s = bulk_str(value) if s is None:
from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V10 from bingads.v10.bulk.entities import QualityScoreData, PerformanceData from bingads.v10.internal.bulk.string_table import _StringTable from bingads.v10.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity from bingads.v10.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping # from bingads.internal.extensions import bulk_str, csv_to_budget, budget_to_csv from bingads.internal.extensions import * _ShoppingSetting = type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ShoppingSetting')) 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
from bingads.v10.internal.bulk.string_table import _StringTable from six import PY2 import re from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V10, _CAMPAIGN_MANAGEMENT_SERVICE_V10, _CAMPAIGN_OBJECT_FACTORY_V11, _CAMPAIGN_MANAGEMENT_SERVICE_V11 DELETE_VALUE = "delete_value" _BULK_DATETIME_FORMAT = '%m/%d/%Y %H:%M:%S' _BULK_DATETIME_FORMAT_2 = '%m/%d/%Y %H:%M:%S.%f' _BULK_DATE_FORMAT = "%m/%d/%Y" url_splitter = ";\\s*(?=https?://)" custom_param_splitter = "(?<!\\\\);\\s*" custom_param_pattern = "^\\{_(.*?)\\}=(.*$)" BudgetLimitType = _CAMPAIGN_OBJECT_FACTORY_V10.create('BudgetLimitType') DynamicSearchAdsSetting = _CAMPAIGN_OBJECT_FACTORY_V10.create('DynamicSearchAdsSetting') Webpage = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:Webpage') WebpageConditionOperand = _CAMPAIGN_OBJECT_FACTORY_V10.create('WebpageConditionOperand') RemarketingRule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:RemarketingRule') PageVisitorsRule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:PageVisitorsRule') PageVisitorsWhoVisitedAnotherPageRule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:PageVisitorsWhoVisitedAnotherPageRule') PageVisitorsWhoDidNotVisitAnotherPageRule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:PageVisitorsWhoDidNotVisitAnotherPageRule') CustomEventsRule = _CAMPAIGN_OBJECT_FACTORY_V10.create('ns0:CustomEventsRule') StringOperator = _CAMPAIGN_OBJECT_FACTORY_V10.create('StringOperator') NumberOperator = _CAMPAIGN_OBJECT_FACTORY_V10.create('NumberOperator') AudienceCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('AudienceCriterion') BidMultiplier = _CAMPAIGN_OBJECT_FACTORY_V11.create('BidMultiplier')
from bingads.v10.internal.bulk.mappings import _SimpleBulkMapping from bingads.v10.internal.bulk.string_table import _StringTable from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V10 from .common import _BulkAdExtensionBase from .common import _BulkAdGroupAdExtensionAssociation from .common import _BulkCampaignAdExtensionAssociation from bingads.internal.extensions import * _ReviewAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V10.create('ReviewAdExtension')) class BulkReviewAdExtension(_BulkAdExtensionBase): """ Represents a review ad extension. This class exposes the :attr:`review_ad_extension` property that can be read and written as fields of the Review Ad Extension record in a bulk file. For more information, see Review Ad Extension at http://go.microsoft.com/fwlink/?LinkID=730546. *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, _ReviewAdExtension):
def parse_ad_group_bid(value): if not value: return None bid = _CAMPAIGN_OBJECT_FACTORY_V10.create('Bid') bid.Amount = float(value) return bid
def parse_ad_rotation(value): if not value: return None ad_rotation = _CAMPAIGN_OBJECT_FACTORY_V10.create('AdRotation') ad_rotation.Type = None if value == DELETE_VALUE else value return ad_rotation
def process_mappings_from_row_values(self, row_values): self.review_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V10.create('ReviewAdExtension') self.review_ad_extension.Type = 'ReviewAdExtension' super(BulkReviewAdExtension, self).process_mappings_from_row_values(row_values) row_values.convert_to_entity(self, BulkReviewAdExtension._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 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)