|
| 1 | +from bingads.v12.bulk.entities import * |
| 2 | +from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 |
| 3 | +from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity |
| 4 | +from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping |
| 5 | +from bingads.v12.internal.bulk.string_table import _StringTable |
| 6 | +from bingads.v12.internal.extensions import * |
| 7 | + |
| 8 | + |
| 9 | +class BulkAdGroupAudienceAssociation(_SingleRecordBulkEntity): |
| 10 | + """ Base class for all Ad Group Audience Association subclasses that can be read or written in a bulk file. |
| 11 | +
|
| 12 | + *See also:* |
| 13 | +
|
| 14 | + * :class:`.BulkAdGroupCustomAudienceAssociation` |
| 15 | + * :class:`.BulkAdGroupInMarketAudienceAssociation` |
| 16 | + * :class:`.BulkAdGroupProductAudienceAssociation` |
| 17 | + * :class:`.BulkAdGroupRemarketingListAssociation` |
| 18 | + * :class:`.BulkAdGroupSimilarRemarketingListAssociation` |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self, |
| 22 | + biddable_ad_group_criterion=None, |
| 23 | + campaign_name=None, |
| 24 | + ad_group_name=None, |
| 25 | + audience_name=None): |
| 26 | + super(BulkAdGroupAudienceAssociation, self).__init__() |
| 27 | + |
| 28 | + self._biddable_ad_group_criterion = biddable_ad_group_criterion |
| 29 | + self._campaign_name = campaign_name |
| 30 | + self._ad_group_name = ad_group_name |
| 31 | + self._audience_name = audience_name |
| 32 | + self._performance_data = None |
| 33 | + |
| 34 | + _MAPPINGS = [ |
| 35 | + _SimpleBulkMapping( |
| 36 | + _StringTable.Status, |
| 37 | + field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), |
| 38 | + csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) |
| 39 | + ), |
| 40 | + _SimpleBulkMapping( |
| 41 | + _StringTable.Id, |
| 42 | + field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), |
| 43 | + csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) |
| 44 | + ), |
| 45 | + _SimpleBulkMapping( |
| 46 | + _StringTable.ParentId, |
| 47 | + field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), |
| 48 | + csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) |
| 49 | + ), |
| 50 | + _SimpleBulkMapping( |
| 51 | + _StringTable.Campaign, |
| 52 | + field_to_csv=lambda c: c.campaign_name, |
| 53 | + csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) |
| 54 | + ), |
| 55 | + _SimpleBulkMapping( |
| 56 | + _StringTable.AdGroup, |
| 57 | + field_to_csv=lambda c: c.ad_group_name, |
| 58 | + csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) |
| 59 | + ), |
| 60 | + _SimpleBulkMapping( |
| 61 | + _StringTable.Audience, |
| 62 | + field_to_csv=lambda c: c.audience_name, |
| 63 | + csv_to_field=lambda c, v: setattr(c, 'audience_name', v) |
| 64 | + ), |
| 65 | + _SimpleBulkMapping( |
| 66 | + _StringTable.BidAdjustment, |
| 67 | + field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), |
| 68 | + csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) |
| 69 | + ), |
| 70 | + _SimpleBulkMapping( |
| 71 | + _StringTable.AudienceId, |
| 72 | + field_to_csv=lambda c: field_to_csv_CriterionAudienceId(c.biddable_ad_group_criterion), |
| 73 | + csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(c.biddable_ad_group_criterion, int(v) if v else None) |
| 74 | + ), |
| 75 | + ] |
| 76 | + |
| 77 | + @property |
| 78 | + def biddable_ad_group_criterion(self): |
| 79 | + """ Defines a Biddable Ad Group Criterion """ |
| 80 | + |
| 81 | + return self._biddable_ad_group_criterion |
| 82 | + |
| 83 | + @biddable_ad_group_criterion.setter |
| 84 | + def biddable_ad_group_criterion(self, biddable_ad_group_criterion): |
| 85 | + self._biddable_ad_group_criterion = biddable_ad_group_criterion |
| 86 | + |
| 87 | + @property |
| 88 | + def campaign_name(self): |
| 89 | + """ Defines the name of the Campaign. |
| 90 | +
|
| 91 | + :rtype: str |
| 92 | + """ |
| 93 | + |
| 94 | + return self._campaign_name |
| 95 | + |
| 96 | + @campaign_name.setter |
| 97 | + def campaign_name(self, campaign_name): |
| 98 | + self._campaign_name = campaign_name |
| 99 | + |
| 100 | + @property |
| 101 | + def ad_group_name(self): |
| 102 | + """ Defines the name of the Ad Group |
| 103 | +
|
| 104 | + :rtype: str |
| 105 | + """ |
| 106 | + |
| 107 | + return self._ad_group_name |
| 108 | + |
| 109 | + @ad_group_name.setter |
| 110 | + def ad_group_name(self, ad_group_name): |
| 111 | + self._ad_group_name = ad_group_name |
| 112 | + |
| 113 | + @property |
| 114 | + def audience_name(self): |
| 115 | + """ Defines the name of the Audience |
| 116 | +
|
| 117 | + :rtype: str |
| 118 | + """ |
| 119 | + |
| 120 | + return self._audience_name |
| 121 | + |
| 122 | + @audience_name.setter |
| 123 | + def audience_name(self, audience_name): |
| 124 | + self._audience_name = audience_name |
| 125 | + |
| 126 | + @property |
| 127 | + def performance_data(self): |
| 128 | + return self._performance_data |
| 129 | + |
| 130 | + def process_mappings_from_row_values(self, row_values): |
| 131 | + self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') |
| 132 | + self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' |
| 133 | + self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AudienceCriterion') |
| 134 | + self._biddable_ad_group_criterion.Criterion.Type = 'AudienceCriterion' |
| 135 | + self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') |
| 136 | + self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' |
| 137 | + row_values.convert_to_entity(self, BulkAdGroupAudienceAssociation._MAPPINGS) |
| 138 | + |
| 139 | + self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) |
| 140 | + |
| 141 | + def process_mappings_to_row_values(self, row_values, exclude_readonly_data): |
| 142 | + self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') |
| 143 | + self.convert_to_values(row_values, BulkAdGroupAudienceAssociation._MAPPINGS) |
| 144 | + |
| 145 | + PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values) |
| 146 | + |
| 147 | + def read_additional_data(self, stream_reader): |
| 148 | + super(BulkAdGroupAudienceAssociation, self).read_additional_data(stream_reader) |
0 commit comments