Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_rule_PageVisitorsWhoVisitedAnotherPage(rule_str):
rule = _CAMPAIGN_OBJECT_FACTORY_V13.create('PageVisitorsWhoVisitedAnotherPageRule')
rule.Type = 'PageVisitorsWhoVisitedAnotherPage'
groups_split = '))) and ((('
groups_string_list = rule_str.split(groups_split)
rule.RuleItemGroups = parse_rule_groups(groups_string_list[0])
rule.AnotherRuleItemGroups = parse_rule_groups(groups_string_list[1])
return rule
_SimpleBulkMapping(
_StringTable.Radius,
field_to_csv=lambda c: field_to_csv_Radius(c.biddable_ad_group_criterion),
csv_to_field=lambda c, v: csv_to_field_Radius(c.biddable_ad_group_criterion, int(v) if v else None)
),
_SimpleBulkMapping(
_StringTable.Unit,
field_to_csv=lambda c: field_to_csv_RadiusUnit(c.biddable_ad_group_criterion),
csv_to_field=lambda c, v: csv_to_field_RadiusUnit(c.biddable_ad_group_criterion, v)
),
_SimpleBulkMapping(
_StringTable.Latitude,
field_to_csv=lambda c: field_to_csv_LatitudeDegrees(c.biddable_ad_group_criterion),
csv_to_field=lambda c, v: csv_to_field_LatitudeDegrees(c.biddable_ad_group_criterion, float(v) if v else None)
),
_SimpleBulkMapping(
_StringTable.Longitude,
field_to_csv=lambda c: field_to_csv_LongitudeDegrees(c.biddable_ad_group_criterion),
csv_to_field=lambda c, v: csv_to_field_LongitudeDegrees(c.biddable_ad_group_criterion, float(v) if v else None)
),
]
@property
def biddable_ad_group_criterion(self):
""" Defines a Ad Group Criterion """
return self._biddable_ad_group_criterion
@biddable_ad_group_criterion.setter
def biddable_ad_group_criterion(self, biddable_ad_group_criterion):
self._biddable_ad_group_criterion = biddable_ad_group_criterion
super(_BulkDeviceOsTargetBid, self).__init__(
status=status,
target_id=target_id,
entity_id=entity_id,
entity_name=entity_name,
parent_entity_name=parent_entity_name
)
_MAPPINGS = [
_SimpleBulkMapping(
header=_StringTable.Target,
field_to_csv=lambda c: bulk_str(c.device_os_target_bid.DeviceName),
csv_to_field=lambda c, v: setattr(c.device_os_target_bid, 'DeviceName', v),
),
_SimpleBulkMapping(
header=_StringTable.OsNames,
field_to_csv=lambda c: ';'.join(
c.device_os_target_bid.OSNames.string) if c.device_os_target_bid.OSNames.string else None,
csv_to_field=lambda c, v: setattr(
c.device_os_target_bid.OSNames,
'string',
list(filter(None, v.split(';'))) if v else [],
),
),
_SimpleBulkMapping(
header=_StringTable.BidAdjustment,
field_to_csv=lambda c: bulk_str(c.device_os_target_bid.BidAdjustment),
csv_to_field=lambda c, v: setattr(c.device_os_target_bid, 'BidAdjustment', int(v))
),
]
@property
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_V11.create('EnhancedCpcBiddingScheme')
elif value == 'InheritFromParent':
entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V11.create('InheritFromParentBiddingScheme')
elif value == 'MaxConversions':
entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V11.create('MaxConversionsBiddingScheme')
elif value == 'ManualCpc':
entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V11.create('ManualCpcBiddingScheme')
elif value == 'TargetCpa':
entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V11.create('TargetCpaBiddingScheme')
elif value == 'MaxClicks':
entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V11.create('MaxClicksBiddingScheme')
else:
raise ValueError('Unknown Bid Strategy Type')
entity.BiddingScheme.Type = value
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_V11.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)
def process_mappings_from_row_values(self, row_values):
self.location_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V11.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_V11.create('GeoPoint')
super(BulkLocationAdExtension, self).process_mappings_from_row_values(row_values)
row_values.convert_to_entity(self, BulkLocationAdExtension._MAPPINGS)
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')
AgeCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('AgeCriterion')
DayTimeCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('DayTimeCriterion')
DeviceCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('DeviceCriterion')
GenderCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('GenderCriterion')
LocationCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('LocationCriterion')
LocationIntentCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('LocationIntentCriterion')
RadiusCriterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('RadiusCriterion')
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):
def process_mappings_from_row_values(self, row_values):
self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('BiddableAdGroupCriterion')
self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'
self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('DeviceCriterion')
self._biddable_ad_group_criterion.Criterion.Type = 'DeviceCriterion'
self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V11.create('BidMultiplier')
self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier'
row_values.convert_to_entity(self, BulkAdGroupDeviceCriterion._MAPPINGS)
def process_mappings_from_row_values(self, row_values):
self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('BiddableCampaignCriterion')
self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion'
self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V11.create('AgeCriterion')
self._biddable_campaign_criterion.Criterion.Type = 'AgeCriterion'
self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V11.create('BidMultiplier')
self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier'
row_values.convert_to_entity(self, BulkCampaignAgeCriterion._MAPPINGS)
def parse_rule_PageVisitors(rule_str):
rule = _CAMPAIGN_OBJECT_FACTORY_V11.create('ns0:PageVisitorsRule')
rule.Type = 'PageVisitors'
rule.RuleItemGroups = parse_rule_groups(rule_str)
return rule