Skip to content

Commit

Permalink
update to version 11.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
qitia committed Jul 10, 2017
1 parent 4b997f4 commit a127702
Show file tree
Hide file tree
Showing 38 changed files with 12,388 additions and 221 deletions.
89 changes: 74 additions & 15 deletions bingads/internal/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,43 @@ def budget_to_csv(bulk_campaign, row_values):
else:
row_values[_StringTable.Budget] = bulk_str(bulk_campaign.campaign.MonthlyBudget)


# TODO as version specific logic added, consider to separate extensions with ap versions
def csv_to_budget_v11(row_values, bulk_campaign):
success, budget_type = row_values.try_get_value(_StringTable.BudgetType)
if not success or not budget_type:
def csv_to_biddingscheme(row_values, bulk_campaign):
success, bid_strategy_type = row_values.try_get_value(_StringTable.BidStrategyType)
if not success or not bid_strategy_type:
return

success, budget_row_value = row_values.try_get_value(_StringTable.Budget)
if not success:
return
budget_value = float(budget_row_value) if budget_row_value else None
csv_to_field_BidStrategyType(bulk_campaign.campaign, bid_strategy_type)

bulk_campaign.campaign.BudgetType = budget_type
bulk_campaign.campaign.DailyBudget = budget_value
success, max_cpc_row_value = row_values.try_get_value(_StringTable.BidStrategyMaxCpc)
max_cpc_value = float(max_cpc_row_value) if max_cpc_row_value else None

success, target_cpa_row_value = row_values.try_get_value(_StringTable.BidStrategyTargetCpa)
target_cpa_value = parse_bid(target_cpa_row_value) if target_cpa_row_value else None

def budget_to_csv_v11(bulk_campaign, row_values):
budget_type = bulk_campaign.campaign.BudgetType
if not budget_type:
if bid_strategy_type == 'MaxConversions':
bulk_campaign.campaign.BiddingScheme.MaxCpc = max_cpc_value
elif bid_strategy_type == 'MaxClicks':
bulk_campaign.campaign.BiddingScheme.MaxCpc = max_cpc_value
elif bid_strategy_type == 'TargetCpa':
bulk_campaign.campaign.BiddingScheme.MaxCpc = max_cpc_value
bulk_campaign.campaign.BiddingScheme.TargetCpa = target_cpa_value


def biddingscheme_to_csv(bulk_campaign, row_values):
bid_strategy_type = field_to_csv_BidStrategyType(bulk_campaign.campaign)

if not bid_strategy_type:
return
row_values[_StringTable.Budget] = bulk_str(bulk_campaign.campaign.DailyBudget)

row_values[_StringTable.BidStrategyType] = bid_strategy_type

if bid_strategy_type == 'MaxConversions':
row_values[_StringTable.BidStrategyMaxCpc] = bid_bulk_str(bulk_campaign.campaign.BiddingScheme.MaxCpc.Bid)
elif bid_strategy_type == 'MaxClicks':
row_values[_StringTable.BidStrategyMaxCpc] = bid_bulk_str(bulk_campaign.campaign.BiddingScheme.MaxCpc.Bid)
elif bid_strategy_type == 'TargetCpa':
row_values[_StringTable.BidStrategyMaxCpc] = bid_bulk_str(bulk_campaign.campaign.BiddingScheme.MaxCpc.Bid)
row_values[_StringTable.BidStrategyTargetCpa] = bulk_str(bulk_campaign.campaign.BiddingScheme.TargetCpa)


def bulk_optional_str(value):
Expand Down Expand Up @@ -296,6 +312,33 @@ def field_to_csv_Urls(entity):
return None
return '; '.join(entity.string)

def csv_to_field_CampaignLanguages(entity, value):
"""
set Languages string field
:param entity: Languages
:param value: the content in csv
:return:set field values
"""
if value is None or value == '':
return
splitter = re.compile(';')
entity.string = splitter.split(value)


def field_to_csv_CampaignLanguages(entity):
"""
parse entity to csv content
:param entity: Languages
:return: csv content
"""
if entity is None:
return None
if entity.string is None:
return DELETE_VALUE
if len(entity.string) == 0:
return None
return '; '.join(entity.string)


def field_to_csv_BidStrategyType(entity):
"""
Expand Down Expand Up @@ -444,6 +487,22 @@ def parse_keyword_bid(value):
return bid


def bid_bulk_str(value):
if value is None:
return DELETE_VALUE
if value.Amount is None:
return None
return bulk_str(value.Amount)


def parse_bid(value):
bid = _CAMPAIGN_OBJECT_FACTORY_V10.create('Bid')
if not value:
bid.Amount = None
else:
bid.Amount = float(value)
return bid

def minute_bulk_str(value):
if value == 'Zero':
return '0'
Expand Down
2 changes: 1 addition & 1 deletion bingads/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = '11.5.2'
VERSION = '11.5.3'
BULK_FORMAT_VERSION = '3.0'
BULK_FORMAT_VERSION_4 = '4.0'
BULK_FORMAT_VERSION_5 = '5.0'
Expand Down
4 changes: 2 additions & 2 deletions bingads/v10/bulk/entities/bulk_ad_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def performance_data(self):
),
_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)
field_to_csv=lambda c: bulk_str(c.ad_group.Language),
csv_to_field=lambda c, v: setattr(c.ad_group, 'Language', v if v else None)
),
_SimpleBulkMapping(
header=_StringTable.BidAdjustment,
Expand Down
13 changes: 6 additions & 7 deletions bingads/v10/bulk/entities/bulk_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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'))
Expand Down Expand Up @@ -221,6 +220,11 @@ def _read_sales_country_code(c, v):
field_to_csv=lambda c: c.campaign.TimeZone,
csv_to_field=lambda c, v: setattr(c.campaign, 'TimeZone', v)
),
_SimpleBulkMapping(
header=_StringTable.Language,
field_to_csv=lambda c: field_to_csv_CampaignLanguages(c.campaign.Languages),
csv_to_field=lambda c, v: csv_to_field_CampaignLanguages(c.campaign.Languages, v)
),
_ComplexBulkMapping(budget_to_csv, csv_to_budget),
_SimpleBulkMapping(
header=_StringTable.BidAdjustment,
Expand All @@ -247,7 +251,6 @@ def _read_sales_country_code(c, v):
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)
Expand All @@ -257,11 +260,7 @@ def _read_sales_country_code(c, v):
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)
),
_ComplexBulkMapping(biddingscheme_to_csv, csv_to_biddingscheme),
_SimpleBulkMapping(
header=_StringTable.BudgetId,
field_to_csv=lambda c: bulk_str(c.campaign.BudgetId),
Expand Down
2 changes: 2 additions & 0 deletions bingads/v10/internal/bulk/csv_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class _CsvHeaders:

# Bid Strategy
_StringTable.BidStrategyType,
_StringTable.BidStrategyMaxCpc,
_StringTable.BidStrategyTargetCpa,

# Ad Format Preference
_StringTable.AdFormatPreference,
Expand Down
5 changes: 4 additions & 1 deletion bingads/v10/internal/bulk/string_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class _StringTable:
SyncTime = "Sync Time"
Name = "Name"
LastModifiedTime = "Modified Time"
AdFormatPreference = "Ad Format Preference"

# Entity Types
SemanticVersion = "Format Version"
Expand Down Expand Up @@ -242,7 +243,9 @@ class _StringTable:

# Bid Strategy
BidStrategyType = "Bid Strategy Type"
AdFormatPreference = "Ad Format Preference"
BidStrategyMaxCpc = "Bid Strategy MaxCpc"
BidStrategyTargetCpa = "Bid Strategy TargetCpa"


# Remarketing
RemarketingList = "Remarketing List"
Expand Down
10,190 changes: 10,189 additions & 1 deletion bingads/v10/proxies/campaign_management_service.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bingads/v11/bulk/entities/ad_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .bulk_review_ad_extensions import *
from .bulk_structured_snippet_ad_extensions import *
from .bulk_sitelink2_ad_extensions import *
from .bulk_price_ad_extensions import *
28 changes: 21 additions & 7 deletions bingads/v11/bulk/entities/ad_extensions/bulk_app_ad_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .common import _BulkAdExtensionBase
from .common import _BulkAdGroupAdExtensionAssociation
from .common import _BulkCampaignAdExtensionAssociation
from .common import _BulkAccountAdExtensionAssociation

from bingads.v11.internal.extensions import *


Expand Down Expand Up @@ -72,11 +74,6 @@ def app_ad_extension(self, value):
field_to_csv=lambda c: c.app_ad_extension.DisplayText,
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DisplayText', v)
),
_SimpleBulkMapping(
header=_StringTable.DevicePreference,
field_to_csv=lambda c: bulk_device_preference_str(c.app_ad_extension.DevicePreference),
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DevicePreference', parse_device_preference(v))
),
]

def process_mappings_from_row_values(self, row_values):
Expand All @@ -91,8 +88,26 @@ def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self.convert_to_values(row_values, BulkAppAdExtension._MAPPINGS)


class BulkAccountAppAdExtension(_BulkAccountAdExtensionAssociation):
""" Represents an account level app ad extension.
This class exposes properties that can be read and written
as fields of the Account App Ad Extension record in a bulk file.
For more information, see Account App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

pass

class BulkCampaignAppAdExtension(_BulkCampaignAdExtensionAssociation):
""" Represents an campaign level app ad extension.
""" Represents a campaign level app ad extension.
This class exposes properties that can be read and written
as fields of the Campaign App Ad Extension record in a bulk file.
Expand All @@ -109,7 +124,6 @@ class BulkCampaignAppAdExtension(_BulkCampaignAdExtensionAssociation):

pass


class BulkAdGroupAppAdExtension(_BulkAdGroupAdExtensionAssociation):
""" Represents an ad group level App ad extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .common import _BulkAdExtensionBase
from .common import _BulkAdGroupAdExtensionAssociation
from .common import _BulkCampaignAdExtensionAssociation
from .common import _BulkAccountAdExtensionAssociation

_CalloutAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V11.create('CalloutAdExtension'))

Expand Down Expand Up @@ -69,8 +70,26 @@ def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self.convert_to_values(row_values, BulkCalloutAdExtension._MAPPINGS)


class BulkAccountCalloutAdExtension(_BulkAccountAdExtensionAssociation):
""" Represents an account level callout ad extension.
This class exposes properties that can be read and written
as fields of the Account Callout Ad Extension record in a bulk file.
For more information, see Account Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

pass

class BulkCampaignCalloutAdExtension(_BulkCampaignAdExtensionAssociation):
""" Represents an campaign level callout ad extension.
""" Represents a campaign level callout ad extension.
This class exposes properties that can be read and written
as fields of the Campaign Callout Ad Extension record in a bulk file.
Expand All @@ -87,7 +106,6 @@ class BulkCampaignCalloutAdExtension(_BulkCampaignAdExtensionAssociation):

pass


class BulkAdGroupCalloutAdExtension(_BulkAdGroupAdExtensionAssociation):
""" Represents an ad group level Callout ad extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .common import _BulkAdExtensionBase
from .common import _BulkCampaignAdExtensionAssociation
from .common import _BulkAdGroupAdExtensionAssociation

from .common import _BulkAccountAdExtensionAssociation

_ImageAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V11.create('ImageAdExtension'))

Expand Down Expand Up @@ -83,8 +83,27 @@ def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self.convert_to_values(row_values, BulkImageAdExtension._MAPPINGS)


class BulkAccountImageAdExtension(_BulkAccountAdExtensionAssociation):
""" Represents an account level image ad extension.
This class exposes properties that can be read and written
as fields of the Account Image Ad Extension record in a bulk file.
For more information, see Account Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

pass


class BulkCampaignImageAdExtension(_BulkCampaignAdExtensionAssociation):
""" Represents an campaign level image ad extension.
""" Represents a campaign level image ad extension.
This class exposes properties that can be read and written
as fields of the Campaign Image Ad Extension record in a bulk file.
Expand All @@ -101,7 +120,6 @@ class BulkCampaignImageAdExtension(_BulkCampaignAdExtensionAssociation):

pass


class BulkAdGroupImageAdExtension(_BulkAdGroupAdExtensionAssociation):
""" Represents an ad group level image ad extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .common import *
from .common import _BulkAdExtensionBase
from .common import _BulkCampaignAdExtensionAssociation

from .common import _BulkAccountAdExtensionAssociation

_LocationAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V11.create('LocationAdExtension'))

Expand Down Expand Up @@ -209,8 +209,27 @@ def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self.convert_to_values(row_values, BulkLocationAdExtension._MAPPINGS)


class BulkAccountLocationAdExtension(_BulkAccountAdExtensionAssociation):
""" Represents an account level location ad extension.
This class exposes properties that can be read and written
as fields of the Account Location Ad Extension record in a bulk file.
For more information, see Account Location Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

pass


class BulkCampaignLocationAdExtension(_BulkCampaignAdExtensionAssociation):
""" Represents an campaign level location ad extension.
""" Represents a campaign level location ad extension.
This class exposes properties that can be read and written
as fields of the Campaign Location Ad Extension record in a bulk file.
Expand All @@ -225,4 +244,4 @@ class BulkCampaignLocationAdExtension(_BulkCampaignAdExtensionAssociation):
* :class:`.BulkFileWriter`
"""

pass
pass
Loading

0 comments on commit a127702

Please sign in to comment.