|
6 | 6 | from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping |
7 | 7 | from bingads.v12.internal.extensions import * |
8 | 8 |
|
| 9 | +def coop_setting_to_csv(bulk_ad_group, row_values): |
| 10 | + if not bulk_ad_group.ad_group.Settings or not bulk_ad_group.ad_group.Settings.Setting: |
| 11 | + return |
| 12 | + settings = [setting for setting in bulk_ad_group.ad_group.Settings.Setting if isinstance(setting, CoOpSetting_Type)] |
| 13 | + if len(settings) == 0: |
| 14 | + return |
| 15 | + if len(settings) != 1: |
| 16 | + raise ValueError('Can only have 1 CoOpSetting in AdGroup Settings.') |
| 17 | + |
| 18 | + row_values[_StringTable.MaximumBid] = settings[0].BidMaxValue |
| 19 | + row_values[_StringTable.BidBoostValue] = settings[0].BidBoostValue |
| 20 | + row_values[_StringTable.BidOption] = settings[0].BidOption |
| 21 | + pass |
| 22 | + |
| 23 | +def csv_to_coop_setting(row_values, bulk_ad_group): |
| 24 | + maximum_bid_success, maximum_bid = row_values.try_get_value(_StringTable.MaximumBid) |
| 25 | + bid_boost_value_success, bid_boost_value = row_values.try_get_value(_StringTable.BidBoostValue) |
| 26 | + bid_option_success, bid_option = row_values.try_get_value(_StringTable.BidOption) |
| 27 | + |
| 28 | + if maximum_bid_success or bid_boost_value_success or bid_option_success: |
| 29 | + coop_setting = _CAMPAIGN_OBJECT_FACTORY_V12.create('CoOpSetting') |
| 30 | + coop_setting.Type = 'CoOpSetting' |
| 31 | + coop_setting.BidOption = bid_option if bid_option else None |
| 32 | + coop_setting.BidBoostValue = float(bid_boost_value) if bid_boost_value else None |
| 33 | + coop_setting.BidMaxValue = float(maximum_bid) if maximum_bid else None |
| 34 | + bulk_ad_group.ad_group.Settings.Setting.append(coop_setting) |
| 35 | + pass |
| 36 | + |
9 | 37 | def bidding_scheme_to_csv(bulk_ad_group, row_values): |
10 | 38 | bid_strategy_type = field_to_csv_BidStrategyType(bulk_ad_group.ad_group) |
11 | 39 | if not bid_strategy_type: |
@@ -216,21 +244,8 @@ def performance_data(self): |
216 | 244 | field_to_csv=lambda c: bulk_str(c.ad_group.PrivacyStatus), |
217 | 245 | csv_to_field=lambda c, v: setattr(c.ad_group, 'PrivacyStatus', v if v else None) |
218 | 246 | ), |
219 | | - _SimpleBulkMapping( |
220 | | - header=_StringTable.BidOption, |
221 | | - field_to_csv=lambda c: bid_option_to_csv(c.ad_group), |
222 | | - csv_to_field=lambda c, v: csv_to_bid_option(c.ad_group, v) |
223 | | - ), |
224 | | - _SimpleBulkMapping( |
225 | | - header=_StringTable.BidBoostValue, |
226 | | - field_to_csv=lambda c: bid_boost_value_to_csv(c.ad_group), |
227 | | - csv_to_field=lambda c, v: csv_to_bid_boost_value(c.ad_group, v) |
228 | | - ), |
229 | | - _SimpleBulkMapping( |
230 | | - header=_StringTable.MaximumBid, |
231 | | - field_to_csv=lambda c: maximum_bid_to_csv(c.ad_group), |
232 | | - csv_to_field=lambda c, v: csv_to_maximum_bid(c.ad_group, v) |
233 | | - ), |
| 247 | + |
| 248 | + _ComplexBulkMapping(coop_setting_to_csv, csv_to_coop_setting), |
234 | 249 | ] |
235 | 250 |
|
236 | 251 | def process_mappings_from_row_values(self, row_values): |
|
0 commit comments