Skip to content

Commit

Permalink
update to version 11.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
qitia committed Aug 8, 2017
1 parent 007a5d7 commit c3d5f6e
Show file tree
Hide file tree
Showing 13 changed files with 1,200 additions and 17 deletions.
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.3'
VERSION = '11.5.4'
BULK_FORMAT_VERSION = '3.0'
BULK_FORMAT_VERSION_4 = '4.0'
BULK_FORMAT_VERSION_5 = '5.0'
Expand Down
2 changes: 2 additions & 0 deletions bingads/v11/bulk/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
from .bulk_negative_sites import *
from .audiences import *
from .target_criterions import *
from .labels import *
from .bulk_offline_conversion import *
34 changes: 28 additions & 6 deletions bingads/v11/bulk/entities/bulk_ad_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@

from bingads.v11.internal.bulk.string_table import _StringTable
from bingads.v11.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping
from bingads.v11.internal.extensions import *


def bidding_scheme_to_csv(bulk_ad_group, row_values):
bid_strategy_type = field_to_csv_BidStrategyType(bulk_ad_group.ad_group)
if not bid_strategy_type:
return
row_values[_StringTable.BidStrategyType] = bid_strategy_type
if bid_strategy_type == 'InheritFromParent' \
and hasattr(bulk_ad_group.ad_group.BiddingScheme, 'InheritedBidStrategyType'):
row_values[_StringTable.InheritedBidStrategyType] = bulk_ad_group.ad_group.BiddingScheme.InheritedBidStrategyType


def csv_to_bidding_scheme(row_values, bulk_ad_group):
success, bid_strategy_type = row_values.try_get_value(_StringTable.BidStrategyType)
if not success or not bid_strategy_type:
return
csv_to_field_BidStrategyType(bulk_ad_group.ad_group, bid_strategy_type)
if bid_strategy_type == 'InheritFromParent':
bulk_ad_group.ad_group.BiddingScheme.Type = "InheritFromParent"
success, inherited_bid_strategy_type = row_values.try_get_value(_StringTable.InheritedBidStrategyType)
if success and inherited_bid_strategy_type != '':
bulk_ad_group.ad_group.BiddingScheme.InheritedBidStrategyType = inherited_bid_strategy_type
elif hasattr(bulk_ad_group.ad_group.BiddingScheme, 'InheritedBidStrategyType'):
del bulk_ad_group.ad_group.BiddingScheme.InheritedBidStrategyType
else:
bulk_ad_group.ad_group.BiddingScheme.Type = bid_strategy_type


class BulkAdGroup(_SingleRecordBulkEntity):
""" Represents an ad group.
Expand Down Expand Up @@ -206,11 +232,7 @@ def performance_data(self):
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)
),
_ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),
_SimpleBulkMapping(
header=_StringTable.RemarketingTargetingSetting,
field_to_csv=lambda c: bulk_str(c.ad_group.RemarketingTargetingSetting),
Expand Down
34 changes: 28 additions & 6 deletions bingads/v11/bulk/entities/bulk_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@
from bingads.v11.bulk.entities import *
from bingads.v11.internal.bulk.string_table import _StringTable
from bingads.v11.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping
from bingads.v11.internal.extensions import *


def bidding_scheme_to_csv(bulk_keyword, row_values):
bid_strategy_type = field_to_csv_BidStrategyType(bulk_keyword.keyword)
if not bid_strategy_type:
return
row_values[_StringTable.BidStrategyType] = bid_strategy_type
if bid_strategy_type == 'InheritFromParent' \
and hasattr(bulk_keyword.keyword.BiddingScheme, 'InheritedBidStrategyType'):
row_values[_StringTable.InheritedBidStrategyType] = bulk_keyword.keyword.BiddingScheme.InheritedBidStrategyType


def csv_to_bidding_scheme(row_values, bulk_keyword):
success, bid_strategy_type = row_values.try_get_value(_StringTable.BidStrategyType)
if not success or not bid_strategy_type:
return
csv_to_field_BidStrategyType(bulk_keyword.keyword, bid_strategy_type)
if bid_strategy_type == 'InheritFromParent':
bulk_keyword.keyword.BiddingScheme.Type = "InheritFromParent"
success, inherited_bid_strategy_type = row_values.try_get_value(_StringTable.InheritedBidStrategyType)
if success and inherited_bid_strategy_type != '':
bulk_keyword.keyword.BiddingScheme.InheritedBidStrategyType = inherited_bid_strategy_type
elif hasattr(bulk_keyword.keyword.BiddingScheme, 'InheritedBidStrategyType'):
del bulk_keyword.keyword.BiddingScheme.InheritedBidStrategyType
else:
bulk_keyword.keyword.BiddingScheme.Type = bid_strategy_type


class BulkKeyword(_SingleRecordBulkEntity):
""" Represents a keyword that can be read or written in a bulk file.
Expand Down Expand Up @@ -242,11 +268,7 @@ def bid_suggestions(self):
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)
),
_ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),
]

def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
Expand Down
97 changes: 97 additions & 0 deletions bingads/v11/bulk/entities/bulk_offline_conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from __future__ import print_function
from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V11
from bingads.v11.internal.bulk.string_table import _StringTable
from bingads.v11.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping
from bingads.v11.internal.extensions import *


class BulkOfflineConversion(_SingleRecordBulkEntity):
""" Represents an offline conversion that can be read or written in a bulk file.
This class exposes the :attr:`offline_conversion` property that can be read and written as fields of the Keyword record in a bulk file.
Properties of this class and of classes that it is derived from, correspond to fields of the Keyword record in a bulk file.
For more information, see Keyword at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

def __init__(self, offline_conversion=None):
super(BulkOfflineConversion, self).__init__()
self._offline_conversion = offline_conversion

@property
def offline_conversion(self):
""" The offline conversion Data Object of the Campaign Management Service.
"""

return self._offline_conversion

@offline_conversion.setter
def offline_conversion(self, value):
self._offline_conversion = value

_MAPPINGS = [
_SimpleBulkMapping(
header=_StringTable.ConversionCurrencyCode,
field_to_csv=lambda c: c.offline_conversion.ConversionCurrencyCode,
csv_to_field=lambda c, v: setattr(
c.offline_conversion,
'ConversionCurrencyCode',
v
)
),
_SimpleBulkMapping(
header=_StringTable.ConversionName,
field_to_csv=lambda c: c.offline_conversion.ConversionName,
csv_to_field=lambda c, v: setattr(
c.offline_conversion,
'ConversionName',
v
)
),
_SimpleBulkMapping(
header=_StringTable.MicrosoftClickId,
field_to_csv=lambda c: c.offline_conversion.MicrosoftClickId,
csv_to_field=lambda c, v: setattr(
c.offline_conversion,
'MicrosoftClickId',
v
)
),
_SimpleBulkMapping(
header=_StringTable.ConversionValue,
field_to_csv=lambda c: c.offline_conversion.ConversionValue,
csv_to_field=lambda c, v: setattr(
c.offline_conversion,
'ConversionValue',
float(v) if v else None
)
),
_SimpleBulkMapping(
header=_StringTable.ConversionTime,
field_to_csv=lambda c: bulk_datetime_str(c.offline_conversion.ConversionTime),
csv_to_field=lambda c, v: setattr(
c.offline_conversion,
'ConversionTime',
parse_datetime(v) if v else None
)
),
]

def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self._validate_property_not_null(self._offline_conversion, 'offline_conversion')
self.convert_to_values(row_values, BulkOfflineConversion._MAPPINGS)

def process_mappings_from_row_values(self, row_values):
self._offline_conversion = _CAMPAIGN_OBJECT_FACTORY_V11.create('OfflineConversion')
row_values.convert_to_entity(self, BulkOfflineConversion._MAPPINGS)

def read_additional_data(self, stream_reader):
super(BulkOfflineConversion, self).read_additional_data(stream_reader)
5 changes: 5 additions & 0 deletions bingads/v11/bulk/entities/labels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__author__ = 'Bing Ads SDK Team'
__email__ = '[email protected]'

from .bulk_label import *
from .bulk_label_associations import *
104 changes: 104 additions & 0 deletions bingads/v11/bulk/entities/labels/bulk_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from __future__ import print_function
from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V11
from bingads.v11.internal.bulk.string_table import _StringTable
from bingads.v11.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity
from bingads.v11.internal.bulk.mappings import _SimpleBulkMapping
from bingads.v11.internal.extensions import *


class BulkLabel(_SingleRecordBulkEntity):
""" Represents a label that can be read or written in a bulk file.
This class exposes the :attr:`label` property that can be read and written as fields of the Keyword record in a bulk file.
Properties of this class and of classes that it is derived from, correspond to fields of the Keyword record in a bulk file.
For more information, see Keyword at https://go.microsoft.com/fwlink/?linkid=846127.
*See also:*
* :class:`.BulkServiceManager`
* :class:`.BulkOperation`
* :class:`.BulkFileReader`
* :class:`.BulkFileWriter`
"""

def __init__(self, label=None, status=None):
super(BulkLabel, self).__init__()
self._label = label
self._status = status

@property
def label(self):
""" The Label Data Object of the Campaign Management Service.
A subset of Label properties are available in the Ad Group record.
"""

return self._label

@label.setter
def label(self, value):
self._label = 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

_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: c.label.Id,
csv_to_field=lambda c, v: setattr(
c.label,
'Id',
int(v) if v else None
)
),
_SimpleBulkMapping(
header=_StringTable.ColorCode,
field_to_csv=lambda c: c.label.ColorCode,
csv_to_field=lambda c, v: setattr(
c.label,
'ColorCode',
v
)
),
_SimpleBulkMapping(
header=_StringTable.Description,
field_to_csv=lambda c: c.label.Description,
csv_to_field=lambda c, v: setattr(c.label, 'Description', v)
),
_SimpleBulkMapping(
header=_StringTable.Label,
field_to_csv=lambda c: c.label.Name,
csv_to_field=lambda c, v: setattr(c.label, 'Name', v)
),
]

def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
self._validate_property_not_null(self._label, 'label')
self.convert_to_values(row_values, BulkLabel._MAPPINGS)

def process_mappings_from_row_values(self, row_values):
self._label = _CAMPAIGN_OBJECT_FACTORY_V11.create('Label')
row_values.convert_to_entity(self, BulkLabel._MAPPINGS)

def read_additional_data(self, stream_reader):
super(BulkLabel, self).read_additional_data(stream_reader)
Loading

0 comments on commit c3d5f6e

Please sign in to comment.