diff --git a/HISTORY.rst b/HISTORY.rst index 8e20fdd2..874da3b8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,13 @@ .. :changelog: Release History +13.0.1(2019-11-08) ++++++++++++++++++++++++++ +* Updated Bing Ads API Version 13 service proxies to reflect recent interface changes. For details please see the Bing Ads API Release Notes. +* Removed support for Bing Ads API Version 12 i.e., removed the service proxies and bulk entities. +* Added mappings for the "Target Ad Group Id" and "Target Campaign Id" bulk columns in BulkFeedItem. +* Added mappings for the "Include View Through Conversions" and "Profile Expansion Enabled" bulk columns in BulkAccount. + 12.13.6(2019-10-12) +++++++++++++++++++++++++ * Mapped the Experiment Type column to ExperimentType via BulkExperiment. diff --git a/MANIFEST.in b/MANIFEST.in index fda0d943..9aab48e6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include *.rst *.py *.txt include LICENSE -include bingads/v12/proxies/*xml include bingads/v13/proxies/*xml diff --git a/README.rst b/README.rst index b52889e0..ec98c61f 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Bing Ads Python SDK :target: https://pypi.python.org/pypi/bingads -The Bing Ads Python Software Development Kit (SDK) Version 12.13 enhances the experience of developing Bing Ads applications +The Bing Ads Python Software Development Kit (SDK) Version 13.0 enhances the experience of developing Bing Ads applications with the Python programming language. The SDK includes proxy classes for all Bing Ads API web services and abstracts the low level details of authentication with OAuth. You can also read and write bulk files with the SDK BulkFileReader and BulkFileWriter, diff --git a/bingads/authorization.py b/bingads/authorization.py index 87389322..7c464d17 100644 --- a/bingads/authorization.py +++ b/bingads/authorization.py @@ -4,7 +4,7 @@ from urlparse import parse_qs, urlparse from urllib import quote_plus import json - +from datetime import datetime, timedelta import requests from .exceptions import OAuthTokenRequestException @@ -212,6 +212,15 @@ def __init__(self, access_token=None, access_token_expires_in_seconds=None, refr self._access_token_expires_in_seconds = access_token_expires_in_seconds self._refresh_token = refresh_token self._response_json = response_json + self._access_token_received_datetime=datetime.utcnow() + + @property + def access_token_received_datetime(self): + """ The datetime when access token was received + + :rtype: datetime + """ + return self._access_token_received_datetime @property def access_token(self): @@ -231,6 +240,19 @@ def access_token_expires_in_seconds(self): return self._access_token_expires_in_seconds + + @property + def access_token_expired(self): + """ Whether the access token has been expired. + + :rtype: bool + """ + + return self.access_token_expires_in_seconds is not None and \ + self.access_token_expires_in_seconds > 0 and \ + datetime.utcnow() > self.access_token_received_datetime + timedelta(seconds = self.access_token_expires_in_seconds) + + @property def refresh_token(self): """ OAuth refresh token that can be user to refresh an access token. diff --git a/bingads/manifest.py b/bingads/manifest.py index 266f9ffc..e943be6a 100644 --- a/bingads/manifest.py +++ b/bingads/manifest.py @@ -1,5 +1,5 @@ import sys -VERSION = '12.13.6' +VERSION = '13.0.1' BULK_FORMAT_VERSION_5 = '5.0' BULK_FORMAT_VERSION_6 = '6.0' WORKING_NAME = 'BingAdsSDKPython' diff --git a/bingads/service_client.py b/bingads/service_client.py index 075cd6ee..7b7292ab 100644 --- a/bingads/service_client.py +++ b/bingads/service_client.py @@ -1,5 +1,5 @@ -from suds.client import Client, Factory, WebFault, ObjectCache # noqa - +from suds.client import Client, Factory, WebFault +from suds.cache import ObjectCache from .headerplugin import HeaderPlugin from .authorization import * from .service_info import SERVICE_INFO_DICT @@ -7,6 +7,7 @@ from getpass import getuser from tempfile import gettempdir from os import path +from datetime import datetime class ServiceClient: @@ -195,8 +196,6 @@ def _format_version(version): :param version: :return: int version """ - if version == 'v12' or version == 12: - return 12 if version == 'v13' or version == 13: return 13 raise ValueError(str.format('version error: [{0}] is not supported.', version)) @@ -245,7 +244,12 @@ def __init__(self, service_client, name): self._name = name def __call__(self, *args, **kwargs): - need_to_refresh_token = False + need_to_refresh_token = self.service_client.refresh_oauth_tokens_automatically \ + and hasattr(self.service_client.authorization_data, 'authentication') \ + and isinstance(self.service_client.authorization_data.authentication, OAuthAuthorization) \ + and self.service_client.authorization_data.authentication.oauth_tokens is not None \ + and self.service_client.authorization_data.authentication.oauth_tokens.access_token_expired + while True: if need_to_refresh_token: authentication = self.service_client.authorization_data.authentication @@ -293,11 +297,6 @@ def name(self): from suds.sax.text import Text -_CAMPAIGN_MANAGEMENT_SERVICE_V12 = Client( - 'file:///' + pkg_resources.resource_filename('bingads', 'v12/proxies/campaign_management_service.xml')) -_CAMPAIGN_OBJECT_FACTORY_V12 = _CAMPAIGN_MANAGEMENT_SERVICE_V12.factory -_CAMPAIGN_OBJECT_FACTORY_V12.object_cache = {} -_CAMPAIGN_OBJECT_FACTORY_V12.create_without_cache = _CAMPAIGN_OBJECT_FACTORY_V12.create _CAMPAIGN_MANAGEMENT_SERVICE_V13 = Client( 'file:///' + pkg_resources.resource_filename('bingads', 'v13/proxies/campaign_management_service.xml')) _CAMPAIGN_OBJECT_FACTORY_V13 = _CAMPAIGN_MANAGEMENT_SERVICE_V13.factory diff --git a/bingads/service_info.py b/bingads/service_info.py index d0b12d40..63058788 100644 --- a/bingads/service_info.py +++ b/bingads/service_info.py @@ -22,86 +22,6 @@ def __init__(self, name, env, url): self._env = env self._url = url -_SERVICE_INFO_LIST_V12 = [ - # ad insight service - _ServiceInfo( - "adinsight", - "production", - "https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/V12/AdInsightService.svc?singleWsdl" - ), - _ServiceInfo( - "adinsight", - "sandbox", - "https://adinsight.api.sandbox.bingads.microsoft.com/Api/Advertiser/AdInsight/V12/AdInsightService.svc?singleWsdl" - ), - - # bulk service - _ServiceInfo( - "bulk", - "production", - "https://bulk.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/BulkService.svc?singleWsdl" - ), - _ServiceInfo( - "bulk", - "sandbox", - "https://bulk.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/BulkService.svc?singleWsdl" - ), - - # campaign management - _ServiceInfo( - "campaignmanagement", - "production", - "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/CampaignManagementService.svc?singleWsdl" - ), - _ServiceInfo( - "campaignmanagement", - "sandbox", - "https://campaign.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/CampaignManagementService.svc?singleWsdl" - ), - - # customer billing - _ServiceInfo( - "customerbilling", - "production", - "https://clientcenter.api.bingads.microsoft.com/Api/Billing/v12/CustomerBillingService.svc?singleWsdl" - ), - _ServiceInfo( - "customerbilling", - "sandbox", - "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/Billing/v12/CustomerBillingService.svc?singleWsdl" - ), - - # customer management - _ServiceInfo( - "customermanagement", - "production", - "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v12/CustomerManagementService.svc?singleWsdl" - ), - _ServiceInfo( - "customermanagement", - "sandbox", - "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v12/CustomerManagementService.svc?singleWsdl" - ), - - # reporting - _ServiceInfo( - "reporting", - "production", - "https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v12/ReportingService.svc?singleWsdl" - ), - _ServiceInfo( - "reporting", - "sandbox", - "https://reporting.api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/v12/ReportingService.svc?singleWsdl" - ), -] - - -SERVICE_INFO_DICT_V12 = {} - -for service_info in _SERVICE_INFO_LIST_V12: - SERVICE_INFO_DICT_V12[(service_info.name, service_info.env)] = service_info - _SERVICE_INFO_LIST_V13 = [ # ad insight service _ServiceInfo( @@ -182,4 +102,4 @@ def __init__(self, name, env, url): for service_info in _SERVICE_INFO_LIST_V13: SERVICE_INFO_DICT_V13[(service_info.name, service_info.env)] = service_info -SERVICE_INFO_DICT = {12: SERVICE_INFO_DICT_V12, 13: SERVICE_INFO_DICT_V13} +SERVICE_INFO_DICT = {13: SERVICE_INFO_DICT_V13} diff --git a/bingads/v12/__init__.py b/bingads/v12/__init__.py deleted file mode 100644 index 5ae46b47..00000000 --- a/bingads/v12/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - diff --git a/bingads/v12/bulk/__init__.py b/bingads/v12/bulk/__init__.py deleted file mode 100644 index 38c5e415..00000000 --- a/bingads/v12/bulk/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .exceptions import * -from .enums import * -from .bulk_operation_progress_info import * -from .bulk_operation_status import * -from .download_parameters import * -from .upload_parameters import * -from .bulk_operation import * -from .file_reader import * -from .file_writer import * -from .bulk_service_manager import * -from .entities import * diff --git a/bingads/v12/bulk/bulk_operation.py b/bingads/v12/bulk/bulk_operation.py deleted file mode 100644 index bf6cb600..00000000 --- a/bingads/v12/bulk/bulk_operation.py +++ /dev/null @@ -1,375 +0,0 @@ -import time -import contextlib -import ssl -import requests -import zipfile -import os -import six -import sys -import shutil - - -from .bulk_operation_status import * -from .bulk_operation_progress_info import * -from .exceptions import * -from bingads.util import _PollingBlocker, errorcode_of_exception, ratelimit_retry_duration -from bingads.exceptions import * - -from bingads.service_client import ServiceClient -from bingads.manifest import * - - -from requests.adapters import HTTPAdapter -from requests.packages.urllib3.poolmanager import PoolManager - - -class TlsHttpAdapter(HTTPAdapter): - """" Transport adapter that chooses the TLS protocols based on python versions. """ - - def init_poolmanager(self, connections, maxsize, block=False): - self.poolmanager = PoolManager( - num_pools=connections, - maxsize=maxsize, - block=block, - ssl_version=ssl.PROTOCOL_SSLv23 - ) - - -class BulkOperation(object): - """ The base class that can be derived to represent a bulk operation requested by a user. - - You can use either the :class:`.BulkDownloadOperation` or :class:`.BulkUploadOperation` - derived class to poll for the operation status, and then download the results file when available. - """ - - def __init__(self, - request_id, - authorization_data, - poll_interval_in_milliseconds=5000, - environment='production', - tracking_id=None, - **suds_options): - self._request_id = request_id - self._service_client = ServiceClient('BulkService', 12, authorization_data, environment, **suds_options) - self._authorization_data = authorization_data - self._poll_interval_in_milliseconds = poll_interval_in_milliseconds - self._final_status = None - self.tracking_id=tracking_id - - def download_result_file(self, result_file_directory, result_file_name, decompress, overwrite, timeout_in_milliseconds=None): - """ Download file with specified URL and download parameters. - - :param result_file_directory: The download result local directory name. - :type result_file_directory: str - :param result_file_name: The download result local file name. - :type result_file_name: str | None - :param decompress: Determines whether to decompress the ZIP file. - If set to true, the file will be decompressed after download. - The default value is false, in which case the downloaded file is not decompressed. - :type decompress: bool - :param overwrite: Indicates whether the result file should overwrite the existing file if any. - :type overwrite: bool - :param timeout_in_milliseconds: (optional) timeout for download result file in milliseconds - :type timeout_in_milliseconds: int - :return: The download file path. - :rtype: str - """ - - if result_file_directory is None: - raise ValueError('result_file_directory cannot be None.') - - url = self.final_status.result_file_url - if result_file_name is None: - result_file_name = self.request_id - - if decompress: - name, ext = os.path.splitext(result_file_name) - if ext == '.zip': - raise ValueError("Result file can't be decompressed into a file with extension 'zip'." - " Please change the extension of the result_file_name or pass decompress_result_file = false") - zip_file_path = os.path.join(result_file_directory, name + '.zip') - result_file_path = os.path.join(result_file_directory, result_file_name) - else: - result_file_path = os.path.join(result_file_directory, result_file_name) - zip_file_path = result_file_path - - if os.path.exists(result_file_path) and overwrite is False: - if six.PY3: - raise FileExistsError('Result file: {0} exists'.format(result_file_path)) - else: - raise OSError('Result file: {0} exists'.format(result_file_path)) - headers = { - 'User-Agent': USER_AGENT, - } - s = requests.Session() - s.mount('https://', TlsHttpAdapter()) - timeout_seconds = None if timeout_in_milliseconds is None else timeout_in_milliseconds / 1000.0 - try: - r = s.get(url, headers=headers, stream=True, verify=True, timeout=timeout_seconds) - except requests.Timeout as ex: - raise FileDownloadException(ex) - r.raise_for_status() - try: - with open(zip_file_path, 'wb') as f: - for chunk in r.iter_content(chunk_size=4096): - if chunk: - f.write(chunk) - f.flush() - if decompress: - with contextlib.closing(zipfile.ZipFile(zip_file_path)) as compressed: - first = compressed.namelist()[0] - with open(result_file_path, 'wb') as f, compressed.open(first, 'r') as cc: - #f.write(compressed.read(first)) - shutil.copyfileobj(cc, f) - except Exception as ex: - raise ex - finally: - if decompress and os.path.exists(zip_file_path): - os.remove(zip_file_path) - return result_file_path - - def track(self, percent_complete=None): - raise NotImplementedError() - - def get_status(self): - raise NotImplementedError() - - @property - def request_id(self): - """ The request identifier corresponding to the bulk upload or download, depending on the derived type. - - :rtype: str - """ - - return self._request_id - - @property - def final_status(self): - """ Gets the final status of the bulk operation or null if the operation is still running. - - :rtype: BulkOperationStatus - """ - - return self._final_status - - @property - def service_client(self): - """ The internal bulk service client. - - :rtype: ServiceClient - """ - - return self._service_client - - @property - def poll_interval_in_milliseconds(self): - """ The time interval in milliseconds between two status polling attempts. - - :rtype: int - """ - - return self._poll_interval_in_milliseconds - - @poll_interval_in_milliseconds.setter - def poll_interval_in_milliseconds(self, poll_interval): - self._poll_interval_in_milliseconds = poll_interval - - -class BulkDownloadOperation(BulkOperation): - """ Represents a bulk download operation requested by a user. - - You can use this class to poll for the download status, and then download the file when available. - - *Example:* - - The :meth:`.BulkServiceManager.submit_download` method returns an instance of this class. - If for any reason you do not want to wait for the file to be prepared for download, - for example if your application quits unexpectedly or you have other tasks to process, you can - use an instance of :class:`.BulkDownloadOperation` to download the file when it is available. - """ - - def __init__(self, - request_id, - authorization_data, - poll_interval_in_milliseconds=5000, - environment='production', - tracking_id=None, - **suds_options): - super(BulkDownloadOperation, self).__init__( - request_id=request_id, - authorization_data=authorization_data, - poll_interval_in_milliseconds=poll_interval_in_milliseconds, - environment=environment, - tracking_id=tracking_id, - **suds_options - ) - - def track(self, progress=None, timeout_in_milliseconds=None): - """ Runs until the bulk service has finished processing the download or upload request. - - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: The final BulkOperationStatus. - :rtype: BulkOperationStatus - """ - - if self.final_status is not None: - return self.final_status - blocker = _PollingBlocker(self.poll_interval_in_milliseconds, timeout_in_milliseconds) - blocker.wait() - while True: - status = self.get_status() - percentage = int(status.percent_complete) - if progress is not None: - progress(BulkOperationProgressInfo(percentage)) - if status.status == 'InProgress': - blocker.wait() - continue - if status.status != 'Completed': - raise BulkException('Exceptions while bulk download.', status.errors) - self._final_status = status - return self._final_status - - def get_status(self): - """ Track the detailed download status. - - :return: The status of bulk download operation. - :rtype: BulkOperationStatus - """ - - if self.final_status is not None: - return self.final_status - response = self._get_status_with_retry(4) - headers = self.service_client.get_response_header() - self.tracking_id = headers['TrackingId'] if 'TrackingId' in headers else None - status = BulkOperationStatus( - status=response.RequestStatus, - percent_complete=int(response.PercentComplete), - result_file_url=response.ResultFileUrl, - errors=None if response.Errors is None else [ - OperationError( - code=error.Code, - details=error.Details, - error_code=error.ErrorCode, - message=error.Message, - ) for error in response.Errors.OperationError - ] - ) - if status.status == 'Completed' or \ - status.status == 'Failed' or \ - status.status == 'FailedFullSyncRequired': - self._final_status = status - return status - - def _get_status_with_retry(self, retry_times): - while retry_times > 1: - try: - return self.service_client.GetBulkDownloadStatus(RequestId=self.request_id) - except Exception as ex: - retry_times -= 1 - if '117' == errorcode_of_exception(ex): - time.sleep(ratelimit_retry_duration[3 - retry_times]) - else: - time.sleep(1) - return self.service_client.GetBulkDownloadStatus(RequestId=self.request_id) - - -class BulkUploadOperation(BulkOperation): - """ Represents a bulk upload operation requested by a user. - - You can use this class to poll for the upload status, and then download the upload results file when available. - - *Example:* - - The :meth:`.BulkServiceManager.submit_upload` method returns an instance of this class. - If for any reason you do not want to wait for the file to finish uploading, - for example if your application quits unexpectedly or you have other tasks to process, you can - use an instance of :class:`.BulkUploadOperation` to download the upload results file when it is available. - """ - - def __init__(self, - request_id, - authorization_data, - poll_interval_in_milliseconds=5000, - environment='production', - tracking_id=None, - **suds_options): - super(BulkUploadOperation, self).__init__( - request_id=request_id, - authorization_data=authorization_data, - poll_interval_in_milliseconds=poll_interval_in_milliseconds, - environment=environment, - tracking_id=tracking_id, - **suds_options - ) - - def track(self, progress=None, timeout_in_milliseconds=None): - """ Runs until the bulk service has finished processing the download or upload request. - - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: The final BulkOperationStatus. - :rtype: BulkOperationStatus - """ - - if self.final_status is not None: - return self.final_status - blocker = _PollingBlocker(self.poll_interval_in_milliseconds, timeout_in_milliseconds) - blocker.wait() - while True: - status = self.get_status() - percentage = int(status.percent_complete) - if progress is not None: - progress(BulkOperationProgressInfo(percentage)) - if status.status == 'InProgress' or status.status == 'FileUploaded' or status.status == 'PendingFileUpload': - blocker.wait() - continue - if status.status != 'Completed' and status.status != 'CompletedWithErrors': - raise BulkException("Exceptions while bulk upload.", status.errors) - self._final_status = status - return self._final_status - - def get_status(self): - """ Track the detailed upload status. - - :return: The status of bulk upload operation. - :rtype: BulkOperationStatus - """ - - if self.final_status is not None: - return self.final_status - response = self._get_status_with_retry(4) - headers = self.service_client.get_response_header() - self.tracking_id = headers['TrackingId'] if 'TrackingId' in headers else None - status = BulkOperationStatus( - status=response.RequestStatus, - percent_complete=int(response.PercentComplete), - result_file_url=response.ResultFileUrl, - errors=None if response.Errors is None else [ - OperationError( - code=error.Code, - details=error.Details, - error_code=error.ErrorCode, - message=error.Message, - ) for error in response.Errors.OperationError - ] - ) - if status.status == 'Completed' or \ - status.status == 'CompletedWithErrors' or \ - status.status == 'Failed' or \ - status.status == 'Expired' or \ - status.status == 'Aborted': - self._final_status = status - return status - - def _get_status_with_retry(self, retry_times): - while retry_times > 1: - try: - return self.service_client.GetBulkUploadStatus(RequestId=self.request_id) - except Exception as ex: - retry_times -= 1 - if '117' == errorcode_of_exception(ex): - time.sleep(ratelimit_retry_duration[3 - retry_times]) - else: - time.sleep(1) - return self.service_client.GetBulkUploadStatus(RequestId=self.request_id) diff --git a/bingads/v12/bulk/bulk_operation_progress_info.py b/bingads/v12/bulk/bulk_operation_progress_info.py deleted file mode 100644 index f69873b4..00000000 --- a/bingads/v12/bulk/bulk_operation_progress_info.py +++ /dev/null @@ -1,20 +0,0 @@ -class BulkOperationProgressInfo(object): - """ Contains percent complete progress information for the bulk operation.""" - - def __init__(self, percent_complete=0): - """ Initialize a new instance of this class. - - :param percent_complete: (optional) Percent complete progress information for the bulk operation. - :type percent_complete: int - """ - - self._percent_complete = percent_complete - - @property - def percent_complete(self): - """ Percent complete progress information for the bulk operation. - - :rtype: int - """ - - return self._percent_complete diff --git a/bingads/v12/bulk/bulk_operation_status.py b/bingads/v12/bulk/bulk_operation_status.py deleted file mode 100644 index 0eabaff9..00000000 --- a/bingads/v12/bulk/bulk_operation_status.py +++ /dev/null @@ -1,76 +0,0 @@ -class BulkOperationStatus(object): - """ Contains tracking details about the results and status of the corresponding :class:`.BulkDownloadOperation` or :class:`.BulkUploadOperation`. """ - - def __init__(self, - status=None, - percent_complete=None, - result_file_url=None, - errors=None): - """ Initialize a new instance of this class. - - :param status: (optional) The download or upload status. - :type status: str - :param percent_complete: (optional) Percent complete progress information for the bulk operation. - :type percent_complete: int - :param result_file_url: (optional) The download or upload result file Url. - :type result_file_url: str - :param errors: (optional) The list of errors associated with the operation. - :type errors: list[OperationError] - """ - - self._status = status - self._percent_complete = percent_complete - self._result_file_url = result_file_url - self._errors = errors - - @property - def status(self): - """ The download or upload status. - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, value): - self._status = value - - @property - def percent_complete(self): - """ Percent complete progress information for the bulk operation. - - :rtype: int - """ - - return self._percent_complete - - @percent_complete.setter - def percent_complete(self, value): - self._percent_complete = value - - @property - def result_file_url(self): - """ The download or upload result file Url. - - :rtype: str - """ - - return self._result_file_url - - @result_file_url.setter - def result_file_url(self, value): - self._result_file_url = value - - @property - def errors(self): - """ The list of errors associated with the operation. - - :rtype: list[OperationError] - """ - - return self._errors - - @errors.setter - def errors(self, value): - self._errors = value diff --git a/bingads/v12/bulk/bulk_service_manager.py b/bingads/v12/bulk/bulk_service_manager.py deleted file mode 100644 index ff184ef0..00000000 --- a/bingads/v12/bulk/bulk_service_manager.py +++ /dev/null @@ -1,370 +0,0 @@ -import tempfile -import uuid - -from .bulk_operation import * -from .upload_parameters import * -from .file_reader import * -from .file_writer import * -from bingads.manifest import * -from bingads.service_client import ServiceClient -from bingads.authorization import * -from bingads.util import _TimeHelper -from bingads.exceptions import TimeoutException - - -class BulkServiceManager: - """ Provides high level methods for uploading and downloading entities using the Bulk API functionality. - - Also provides methods for submitting upload or download operations. - - *Example:* - - :func:`download_file` will submit the download request to the bulk service, - poll until the status is completed (or returns an error), and downloads the file locally. - If instead you want to manage the low level details you would first call :func:`submit_download`, - wait for the results file to be prepared using either :meth:`.BulkDownloadOperation.get_status` - or :meth:`.BulkDownloadOperation.track`, and then download the file with the - :meth:`.BulkOperation.download_result_file` method. - """ - - def __init__(self, authorization_data, poll_interval_in_milliseconds=5000, environment='production', working_directory=None, **suds_options): - """ Initialize a new instance of this class. - - :param authorization_data: Represents a user who intends to access the corresponding customer and account. - :type authorization_data: AuthorizationData - :param environment: (optional) Represents which API environment to use, default is `production`, you can also pass `sandbox` in - :type environment: str - :param poll_interval_in_milliseconds: (optional) The time interval in milliseconds between two status polling attempts. - The default value is 15000 milliseconds. - :type poll_interval_in_milliseconds: int - :param working_directory: (optional) Directory for storing temporary files needed for some operations - (for example :func:`upload_entities` creates a temporary upload file). - :param suds_options: The suds options need to pass to suds client - """ - - self._environment = environment - self._service_client = ServiceClient('BulkService', 12, authorization_data, environment, **suds_options) - self._authorization_data = authorization_data - self._poll_interval_in_milliseconds = poll_interval_in_milliseconds - self._working_directory = os.path.join(tempfile.gettempdir(), WORKING_NAME) - if working_directory is not None: - self._working_directory = working_directory - # make sure the working directory exists or create it. - if not os.path.exists(self._working_directory): - os.makedirs(self._working_directory) - self._suds_options = suds_options - - def download_file(self, download_parameters, progress=None): - """ Downloads the specified Bulk entities to a local file. - - :param download_parameters: Determines various download parameters, for example where the file should be downloaded. - :type download_parameters: DownloadParameters - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: The downloaded local bulk file path. - :rtype: str - """ - - start_timestamp = _TimeHelper.get_current_time_milliseconds() - operation = self.submit_download(download_parameters._submit_download_parameter) - try: - operation.track(progress, download_parameters.timeout_in_milliseconds) - except TimeoutException: - raise BulkDownloadException("Bulk file download tracking status timeout.") - result_file_directory = self.working_directory - if download_parameters.result_file_directory is not None: - result_file_directory = download_parameters.result_file_directory - download_result_file_timeout = _TimeHelper.get_remaining_time_milliseconds_with_min_value(start_timestamp, download_parameters.timeout_in_milliseconds) - result_file_path = operation.download_result_file( - result_file_directory=result_file_directory, - result_file_name=download_parameters.result_file_name, - decompress=download_parameters.decompress_result_file, - overwrite=download_parameters.overwrite_result_file, - timeout_in_milliseconds=download_result_file_timeout, - ) - return result_file_path - - def download_entities(self, download_parameters, progress=None): - """ Downloads the specified Bulk entities. - - :param download_parameters: Determines various download parameters, for example where the file should be downloaded. - :type download_parameters: DownloadParameters - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: Bulk entity generator. - :rtype: generator[BulkEntity] - """ - - result_file_path = self.download_file(download_parameters, progress) - result_file_type = ResultFileType.full_download \ - if download_parameters.last_sync_time_in_utc is None \ - else ResultFileType.partial_download - with BulkFileReader( - file_path=result_file_path, - result_file_type=result_file_type, - file_type=download_parameters.file_type, - ) as reader: - for entity in reader: - yield entity - - def upload_file(self, file_upload_parameters, progress=None): - """ Uploads the specified Bulk file. - - :param file_upload_parameters: Determines various upload parameters. - :type file_upload_parameters: FileUploadParameters - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: The download local bulk file path. - :rtype: str - """ - - start_timestamp = _TimeHelper.get_current_time_milliseconds() - file_upload_parameters._submit_upload_parameters.timeout_in_milliseconds = file_upload_parameters.timeout_in_milliseconds - operation = self.submit_upload(file_upload_parameters._submit_upload_parameters) - upload_operation_timeout = _TimeHelper.get_remaining_time_milliseconds_with_min_value(start_timestamp, file_upload_parameters.timeout_in_milliseconds) - try: - operation.track(progress, upload_operation_timeout) - except TimeoutException: - raise BulkUploadException("Bulk file upload tracking status timeout.") - result_file_directory = self.working_directory - if file_upload_parameters.result_file_directory is not None: - result_file_directory = file_upload_parameters.result_file_directory - download_result_file_timeout = _TimeHelper.get_remaining_time_milliseconds_with_min_value(start_timestamp, file_upload_parameters.timeout_in_milliseconds) - result_file_path = operation.download_result_file( - result_file_directory=result_file_directory, - result_file_name=file_upload_parameters.result_file_name, - decompress=file_upload_parameters.decompress_result_file, - overwrite=file_upload_parameters.overwrite_result_file, - timeout_in_milliseconds=download_result_file_timeout, - ) - return result_file_path - - def upload_entities(self, entity_upload_parameters, progress=None): - """ Uploads the specified Bulk entities. - - :param entity_upload_parameters: Determines various upload parameters, for example what entities to upload. - :type entity_upload_parameters: EntityUploadParameters - :param progress: (optional) Tracking the percent complete progress information for the bulk operation. - :type progress: BulkOperationProgressInfo -> None - :return: Bulk entity generator. - :rtype: generator[BulkEntity] - """ - - tmp_file = path.join(self.working_directory, '{0}.csv'.format(uuid.uuid1())) - with BulkFileWriter(tmp_file) as writer: - for entity in entity_upload_parameters.entities: - writer.write_entity(entity) - file_upload_parameters = FileUploadParameters( - upload_file_path=tmp_file, - result_file_directory=entity_upload_parameters.result_file_directory, - result_file_name=entity_upload_parameters.result_file_name, - overwrite_result_file=entity_upload_parameters.overwrite_result_file, - response_mode=entity_upload_parameters.response_mode, - compress_upload_file=True, - ) - result_file_path = self.upload_file( - file_upload_parameters=file_upload_parameters, - progress=progress, - ) - with BulkFileReader(result_file_path, result_file_type=ResultFileType.upload) as reader: - for entity in reader: - yield entity - - def submit_download(self, submit_download_parameters): - """ Submits a download request to the Bing Ads bulk service with the specified parameters. - - :param submit_download_parameters: Determines various download parameters, for example what entities to download. - :type submit_download_parameters: SubmitDownloadParameters - :return: The submitted download operation - :rtype: BulkDownloadOperation - """ - - data_scope = None if submit_download_parameters.data_scope is None else ' '.join( - submit_download_parameters.data_scope) - download_file_type = submit_download_parameters.file_type - download_entities = self.service_client.factory.create('ArrayOfDownloadEntity') - download_entities.DownloadEntity = submit_download_parameters.download_entities - - #entities = None if submit_download_parameters.entities is None else ' '.join( - # submit_download_parameters.entities) - - format_version = BULK_FORMAT_VERSION_6 - last_sync_time_in_utc = submit_download_parameters.last_sync_time_in_utc - performance_stats_date_range = submit_download_parameters.performance_stats_date_range - - if submit_download_parameters.campaign_ids is None: - response = self.service_client.DownloadCampaignsByAccountIds( - AccountIds={'long': [self._authorization_data.account_id]}, - DataScope=data_scope, - DownloadFileType=download_file_type, - DownloadEntities=download_entities, - FormatVersion=format_version, - LastSyncTimeInUTC=last_sync_time_in_utc, - PerformanceStatsDateRange=performance_stats_date_range, - ) - headers = self.service_client.get_response_header() - else: - response = self.service_client.DownloadCampaignsByCampaignIds( - Campaigns={ - 'CampaignScope': [ - {'CampaignId': campaign_id, 'ParentAccountId': self._authorization_data.account_id} - for campaign_id in submit_download_parameters.campaign_ids - ] - }, - DataScope=data_scope, - DownloadFileType=download_file_type, - DownloadEntities=download_entities, - FormatVersion=format_version, - LastSyncTimeInUTC=last_sync_time_in_utc, - PerformanceStatsDateRange=performance_stats_date_range, - ) - headers = self.service_client.get_response_header() - operation = BulkDownloadOperation( - request_id=response, - authorization_data=self._authorization_data, - poll_interval_in_milliseconds=self._poll_interval_in_milliseconds, - environment=self._environment, - tracking_id=headers['TrackingId'] if 'TrackingId' in headers else None, - **self.suds_options - ) - return operation - - def submit_upload(self, submit_upload_parameters): - """ Submits a request for a URL where a bulk upload file may be posted. - - :param submit_upload_parameters: - :type submit_upload_parameters: SubmitUploadParameters - :return: The submitted upload operation. - :rtype: BulkUploadOperation - """ - - response = self.service_client.GetBulkUploadUrl( - AccountId=self._authorization_data.account_id, - ResponseMode=submit_upload_parameters.response_mode, - ) - headers = self.service_client.get_response_header() - request_id = response.RequestId - upload_url = response.UploadUrl - - if submit_upload_parameters.rename_upload_file_to_match_request_id: - import os - dir = os.path.dirname(submit_upload_parameters.upload_file_path) - new_file_to_upload = os.path.join(dir, 'upload_' + request_id + '.csv') - os.rename(submit_upload_parameters.upload_file_path, new_file_to_upload) - submit_upload_parameters.upload_file_path = new_file_to_upload - - self._upload_file_by_url( - url=upload_url, - upload_file_path=submit_upload_parameters.upload_file_path, - compress_upload_file=submit_upload_parameters.compress_upload_file, - ) - operation = BulkUploadOperation( - request_id=request_id, - authorization_data=self._authorization_data, - poll_interval_in_milliseconds=self._poll_interval_in_milliseconds, - environment=self._environment, - tracking_id=headers['TrackingId'] if 'TrackingId' in headers else None, - **self.suds_options - ) - return operation - - def _upload_file_by_url(self, url, upload_file_path, compress_upload_file, timeout_in_milliseconds=None): - """ Upload bulk file specified in upload parameters to specified URL - - :param url: The upload target URL. - :type url: str - :param upload_file_path: The fully qualified local path of the upload file. - :type upload_file_path: str - :param compress_upload_file: whether the upload file should be compressed before uploading. - :type compress_upload_file: bool - """ - - _, ext = path.splitext(upload_file_path) - if compress_upload_file and ext != '.zip': - should_compress = True - else: - should_compress = False - - try: - if should_compress: - name, ext = path.splitext(upload_file_path) - zip_file_path = os.path.join(self.working_directory, '{0}_{1}.zip'.format(name, uuid.uuid1())) - - with contextlib.closing(zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED)) as f: - f.write(upload_file_path) - upload_file_path = zip_file_path - headers = { - 'DeveloperToken': self._authorization_data.developer_token, - 'CustomerId': str(self._authorization_data.customer_id), - 'AccountId': str(self._authorization_data.account_id), - 'User-Agent': USER_AGENT, - } - self._authorization_data.authentication.enrich_headers(headers) - - with open(upload_file_path, 'rb') as f: - name, ext = path.splitext(upload_file_path) - - filename = '{0}{1}'.format(uuid.uuid1(), ext) - s = requests.Session() - s.mount('https://', TlsHttpAdapter()) - timeout_seconds = None if timeout_in_milliseconds is None else timeout_in_milliseconds / 1000.0 - try: - r = s.post(url, files={'file': (filename, f)}, verify=True, headers=headers, timeout=timeout_seconds) - except requests.Timeout as ex: - raise FileUploadException(ex) - r.raise_for_status() - except Exception as ex: - raise ex - finally: - if should_compress: - name, ext = path.splitext(upload_file_path) - zip_file_path = name + '.zip' - if path.exists(zip_file_path): - os.remove(zip_file_path) - - @property - def service_client(self): - """ The internal bulk service client. - - :rtype: ServiceClient - """ - - return self._service_client - - @property - def poll_interval_in_milliseconds(self): - """ The time interval in milliseconds between two status polling attempts. - - :rtype: int - """ - - return self._poll_interval_in_milliseconds - - @poll_interval_in_milliseconds.setter - def poll_interval_in_milliseconds(self, poll_interval): - self._poll_interval_in_milliseconds = poll_interval - - @property - def working_directory(self): - """ Directory for storing temporary files needed for some operations (for example :func:`upload_entities` creates a temporary upload file). - - :rtype: str - """ - - return self._working_directory - - @working_directory.setter - def working_directory(self, value): - self._working_directory = value - - @property - def suds_options(self): - """ suds option parameters - - :return: dict - """ - return self._suds_options - - @suds_options.setter - def suds_options(self, value): - self._suds_options = value diff --git a/bingads/v12/bulk/download_parameters.py b/bingads/v12/bulk/download_parameters.py deleted file mode 100644 index 4e4294a6..00000000 --- a/bingads/v12/bulk/download_parameters.py +++ /dev/null @@ -1,374 +0,0 @@ -import os - -class DownloadParameters: - """ Describes the related parameters when downloading file from server. - - such as the type of entities and data scope that you want to download. - """ - - def __init__(self, - result_file_directory=None, - result_file_name=None, - overwrite_result_file=False, - data_scope=None, - download_entities=None, - file_type='Csv', - campaign_ids=None, - last_sync_time_in_utc=None, - performance_stats_date_range=None, - timeout_in_milliseconds=None): - """ Initialize an instance of this class. - - :param result_file_directory: (optional) The directory where the file will be downloaded. - :type result_file_directory: str - :param result_file_name: (optional) The name of the download result file. - :type result_file_name: str - :param overwrite_result_file: (optional) Whether the local result file should be overwritten if it already exists, default is False. - :type overwrite_result_file: bool - :param data_scope: (optional) The scope or types of data to download. - For possible values, see DataScope Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type data_scope: list[str] - :param download_entities: (optional) The type of entities to download. - For possible values, see BulkDownloadEntity Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type download_entities: list[str] - :param file_type: (optional) The extension type of the downloaded file. - For possible values, see DownloadFileType Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type file_type: str - :param campaign_ids: (optional) The campaigns to download. - You can specify a maximum of 1,000 campaigns. The campaigns that you specify must belong to the same account. - :type campaign_ids: list[int] - :param last_sync_time_in_utc: (optional) The last time that you requested a download. - The date and time is expressed in Coordinated Universal Time (UTC). - Typically, you request a full download the first time you call the operation by setting this element to null. - On all subsequent calls you set the last sync time to the time stamp of the previous download. - The download file contains the time stamp of the download in the SyncTime column of the Account record. - Use the time stamp to set LastSyncTimeInUTC the next time that you request a download. - If you specify the last sync time, only those entities that have changed (been updated or deleted) - since the specified date and time will be downloaded. However, if the campaign data has not been previously downloaded, - the operation performs a full download. - :type last_sync_time_in_utc: datetime - :param performance_stats_date_range: (optional) The date range values for the requested performance data in a bulk download. - For possible values, see PerformanceStatsDateRange Data Object at https://go.microsoft.com/fwlink/?linkid=846127. - :type performance_stats_date_range: PerformanceStatsDateRange - :param timeout_in_milliseconds: (optional) timeout for bulk download operations in milliseconds - :type timeout_in_milliseconds: int - """ - - self._result_file_directory = result_file_directory - self._result_file_name = result_file_name - self._decompress_result_file = True - if result_file_name is not None: - _, ext = os.path.splitext(result_file_name) - if ext == '.zip': - self._decompress_result_file = False - self._overwrite_result_file = overwrite_result_file - self._submit_download_parameter = SubmitDownloadParameters( - data_scope=data_scope, - download_entities=download_entities, - file_type=file_type, - campaign_ids=campaign_ids, - last_sync_time_in_utc=last_sync_time_in_utc, - performance_stats_date_range=performance_stats_date_range, - ) - self._timeout_in_milliseconds = timeout_in_milliseconds - - - @property - def result_file_directory(self): - """ The directory where the file will be downloaded. - - :rtype: str - """ - - return self._result_file_directory - - @property - def result_file_name(self): - """ The name of the download result file. - - :rtype: str - """ - - return self._result_file_name - - @property - def overwrite_result_file(self): - """ Whether the local result file should be overwritten if it already exists. - - :rtype: bool - """ - - return self._overwrite_result_file - - @result_file_directory.setter - def result_file_directory(self, result_file_directory): - self._result_file_directory = result_file_directory - - @result_file_name.setter - def result_file_name(self, result_file_name): - self._result_file_name = result_file_name - - @overwrite_result_file.setter - def overwrite_result_file(self, overwrite): - self._overwrite_result_file = overwrite - - @property - def decompress_result_file(self): - """ If need to decompress the result file after download. - - This property is determined by the result_file_name, by default will do decompression. - if the result_file_name has the extension of '.zip' then do not do decompression. - - :rtype: bool - """ - - return self._decompress_result_file - - @property - def data_scope(self): - """ The scope or types of data to download. - - For possible values, see DataScope Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: list[str] - """ - - return self._submit_download_parameter.data_scope - - @data_scope.setter - def data_scope(self, value): - self._submit_download_parameter.data_scope = value - - @property - def download_entities(self): - """ The type of entities to download. - - For possible values, see BulkDownloadEntity Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: list[str] - """ - - return self._submit_download_parameter.download_entities - - @download_entities.setter - def download_entities(self, value): - self._submit_download_parameter.download_entities = value - - @property - def file_type(self): - """ The extension type of the downloaded file. - - For possible values, see DownloadFileType Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: str - """ - - return self._submit_download_parameter.file_type - - @file_type.setter - def file_type(self, value): - self._submit_download_parameter.file_type = value - - @property - def campaign_ids(self): - """ The campaigns to download. - - You can specify a maximum of 1,000 campaigns. The campaigns that you specify must belong to the same account. - - :rtype: list[int] - """ - - return self._submit_download_parameter.campaign_ids - - @campaign_ids.setter - def campaign_ids(self, value): - self._submit_download_parameter.campaign_ids = value - - @property - def last_sync_time_in_utc(self): - """ The last time that you requested a download. - - The date and time is expressed in Coordinated Universal Time (UTC). - Typically, you request a full download the first time you call the operation by setting this element to null. - On all subsequent calls you set the last sync time to the time stamp of the previous download. - The download file contains the time stamp of the download in the SyncTime column of the Account record. - Use the time stamp to set LastSyncTimeInUTC the next time that you request a download. - If you specify the last sync time, only those entities that have changed (been updated or deleted) - since the specified date and time will be downloaded. However, if the campaign data has not been previously downloaded, - the operation performs a full download. - - :rtype: datetime - """ - - return self._submit_download_parameter.last_sync_time_in_utc - - @last_sync_time_in_utc.setter - def last_sync_time_in_utc(self, value): - self._submit_download_parameter.last_sync_time_in_utc = value - - @property - def performance_stats_date_range(self): - """ The date range values for the requested performance data in a bulk download. - - For possible values, see PerformanceStatsDateRange Data Object at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: PerformanceStatsDateRange - """ - - return self._submit_download_parameter.performance_stats_date_range - - @performance_stats_date_range.setter - def performance_stats_date_range(self, value): - self._submit_download_parameter.performance_stats_date_range = value - - @property - def timeout_in_milliseconds(self): - return self._timeout_in_milliseconds - - @timeout_in_milliseconds.setter - def timeout_in_milliseconds(self, value): - self._timeout_in_milliseconds = value - - -class SubmitDownloadParameters(object): - """ Describes the service request parameters such as the type of entities and data scope that you want to download. """ - - def __init__(self, - data_scope=None, - download_entities=None, - file_type='Csv', - campaign_ids=None, - last_sync_time_in_utc=None, - performance_stats_date_range=None): - """ Initialize an object of this class. - - :param data_scope: (optional) The scope or types of data to download. - For possible values, see DataScope Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type data_scope: list[str] - :param download_entities: (optional) The type of entities to download. - For possible values, see BulkDownloadEntity Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type download_entities: list[str] - :param file_type: (optional) The extension type of the downloaded file. - For possible values, see DownloadFileType Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - :type file_type: str - :param campaign_ids: (optional) The campaigns to download. - You can specify a maximum of 1,000 campaigns. The campaigns that you specify must belong to the same account. - :type campaign_ids: list[int] - :param last_sync_time_in_utc: (optional) The last time that you requested a download. - The date and time is expressed in Coordinated Universal Time (UTC). - Typically, you request a full download the first time you call the operation by setting this element to null. - On all subsequent calls you set the last sync time to the time stamp of the previous download. - The download file contains the time stamp of the download in the SyncTime column of the Account record. - Use the time stamp to set LastSyncTimeInUTC the next time that you request a download. - If you specify the last sync time, only those entities that have changed (been updated or deleted) - since the specified date and time will be downloaded. However, if the campaign data has not been previously downloaded, - the operation performs a full download. - :type last_sync_time_in_utc: datetime - :param performance_stats_date_range: (optional) The date range values for the requested performance data in a bulk download. - For possible values, see PerformanceStatsDateRange Data Object at https://go.microsoft.com/fwlink/?linkid=846127. - :type performance_stats_date_range: (optional) PerformanceStatsDateRange - """ - - self._data_scope = data_scope - self._download_entities = download_entities - self._file_type = file_type - self._campaign_ids = campaign_ids - self._last_sync_time_in_utc = last_sync_time_in_utc - self._performance_stats_data_range = performance_stats_date_range - - @property - def data_scope(self): - """ The scope or types of data to download. - - For possible values, see DataScope Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: list[str] - """ - - return self._data_scope - - @data_scope.setter - def data_scope(self, value): - self._data_scope = value - - @property - def download_entities(self): - """ The type of entities to download. - - For possible values, see BulkDownloadEntity Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: list[str] - """ - - return self._download_entities - - @download_entities.setter - def download_entities(self, value): - self._download_entities = value - - @property - def file_type(self): - """ The extension type of the downloaded file. - - For possible values, see DownloadFileType Value Set at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: str - """ - - return self._file_type - - @file_type.setter - def file_type(self, value): - self._file_type = value - - @property - def campaign_ids(self): - """ The campaigns to download. - - You can specify a maximum of 1,000 campaigns. The campaigns that you specify must belong to the same account. - - :rtype: list[int] - """ - - return self._campaign_ids - - @campaign_ids.setter - def campaign_ids(self, value): - self._campaign_ids = value - - @property - def last_sync_time_in_utc(self): - """ The last time that you requested a download. - - The date and time is expressed in Coordinated Universal Time (UTC). - Typically, you request a full download the first time you call the operation by setting this element to null. - On all subsequent calls you set the last sync time to the time stamp of the previous download. - The download file contains the time stamp of the download in the SyncTime column of the Account record. - Use the time stamp to set LastSyncTimeInUTC the next time that you request a download. - If you specify the last sync time, only those entities that have changed (been updated or deleted) - since the specified date and time will be downloaded. However, if the campaign data has not been previously downloaded, - the operation performs a full download. - - :rtype: datetime - """ - - return self._last_sync_time_in_utc - - @last_sync_time_in_utc.setter - def last_sync_time_in_utc(self, value): - self._last_sync_time_in_utc = value - - @property - def performance_stats_date_range(self): - """ The date range values for the requested performance data in a bulk download. - - For possible values, see PerformanceStatsDateRange Data Object at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: PerformanceStatsDateRange - """ - - return self._performance_stats_data_range - - @performance_stats_date_range.setter - def performance_stats_date_range(self, value): - self._performance_stats_data_range = value diff --git a/bingads/v12/bulk/entities/__init__.py b/bingads/v12/bulk/entities/__init__.py deleted file mode 100644 index afc5d3d8..00000000 --- a/bingads/v12/bulk/entities/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .common import * - -from .bulk_error import * -from .bulk_entity import * -from .bid_suggestion_data import * -from .unknown_bulk_entity import * -from .bulk_account import * -from .bulk_budget import * -from .bulk_campaign import * -from .bulk_ad_group import * -from .bulk_keyword import * -from .bulk_campaign_product_scope import * -from .bulk_ad_group_product_partition import * -from .bulk_campaign_negative_dynamic_search_ad_target import * -from .bulk_ad_group_dynamic_search_ad_target import * -from .bulk_ad_group_negative_dynamic_search_ad_target import * - -from .ad_extensions import * -from .bulk_ads import * -from .bulk_negative_keywords import * -from .bulk_negative_sites import * -from .audiences import * -from .target_criterions import * -from .labels import * -from .bulk_offline_conversion import * -from .bulk_experiment import * diff --git a/bingads/v12/bulk/entities/ad_extensions/__init__.py b/bingads/v12/bulk/entities/ad_extensions/__init__.py deleted file mode 100644 index c063d1d0..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -from .common import * - -from .bulk_call_ad_extensions import * -from .bulk_image_ad_extensions import * -from .bulk_location_ad_extensions import * -from .bulk_app_ad_extensions import * -from .bulk_callout_ad_extensions import * -from .bulk_review_ad_extensions import * -from .bulk_structured_snippet_ad_extensions import * -from .bulk_sitelink_ad_extensions import * -from .bulk_price_ad_extensions import * -from .bulk_action_ad_extensions import * \ No newline at end of file diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_action_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_action_ad_extensions.py deleted file mode 100644 index 4cf74bf6..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_action_ad_extensions.py +++ /dev/null @@ -1,178 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - - -_ActionAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ActionAdExtension')) - - -class BulkActionAdExtension(_BulkAdExtensionBase): - """ Represents a action ad extension. - - This class exposes the :attr:`action_ad_extension` property that can be read and written - as fields of the Action Ad Extension record in a bulk file. - - For more information, see Action Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _ActionAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'ActionAdExtension' - )) - super(BulkActionAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - self._action_text = None - - - @property - def action_ad_extension(self): - """ The action ad extension. - - see Action Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @action_ad_extension.setter - def action_ad_extension(self, value): - self._ad_extension = value - - - @property - def action_text(self): - """ The action text. - - """ - - return self._action_text - - @action_text.setter - def action_text(self, value): - self._action_text = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.ActionType, - field_to_csv=lambda c: bulk_str(c.action_ad_extension.ActionType), - csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'ActionType', v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.action_ad_extension.FinalUrls, c.action_ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.action_ad_extension.FinalUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalMobileUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.action_ad_extension.FinalMobileUrls, c.action_ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.action_ad_extension.FinalMobileUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_optional_str(c.action_ad_extension.TrackingUrlTemplate, c.action_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'TrackingUrlTemplate', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.Language, - field_to_csv=lambda c: bulk_optional_str(c.action_ad_extension.Language, c.action_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'Language', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.action_ad_extension), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.action_ad_extension, v) - ), - _SimpleBulkMapping( - header=_StringTable.ActionText, - field_to_csv=lambda c: c.action_text, - csv_to_field=lambda c, v: setattr(c, 'action_text', v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.action_ad_extension.FinalUrlSuffix, c.action_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.action_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('ActionAdExtension') - self.action_ad_extension.Type = 'ActionAdExtension' - super(BulkActionAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkActionAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.action_ad_extension, 'action_ad_extension') - super(BulkActionAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkActionAdExtension._MAPPINGS) - - -class BulkAccountActionAdExtension(_BulkAccountAdExtensionAssociation): - """ Represents an account level action ad extension. - - This class exposes properties that can be read and written - as fields of the Account Action Ad Extension record in a bulk file. - - For more information, see Account Action Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkCampaignActionAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level action ad extension. - - This class exposes properties that can be read and written - as fields of the Campaign Action Ad Extension record in a bulk file. - - For more information, see Campaign Action Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupActionAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level Action ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Action Ad Extension record in a bulk file. - - For more information, see Ad Group Action Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_app_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_app_ad_extensions.py deleted file mode 100644 index 98851bd9..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_app_ad_extensions.py +++ /dev/null @@ -1,148 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - - -_AppAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('AppAdExtension')) - - -class BulkAppAdExtension(_BulkAdExtensionBase): - """ Represents a app ad extension. - - This class exposes the :attr:`app_ad_extension` property that can be read and written - as fields of the App Ad Extension record in a bulk file. - - For more information, see App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _AppAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'AppAdExtension' - )) - super(BulkAppAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def app_ad_extension(self): - """ The app ad extension. - - see App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @app_ad_extension.setter - def app_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.AppPlatform, - field_to_csv=lambda c: c.app_ad_extension.AppPlatform, - csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'AppPlatform', v) - ), - _SimpleBulkMapping( - header=_StringTable.AppStoreId, - field_to_csv=lambda c: c.app_ad_extension.AppStoreId, - csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'AppStoreId', v) - ), - _SimpleBulkMapping( - header=_StringTable.DestinationUrl, - field_to_csv=lambda c: c.app_ad_extension.DestinationUrl, - csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DestinationUrl', v) - ), - _SimpleBulkMapping( - header=_StringTable.Text, - 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.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.app_ad_extension.FinalUrlSuffix, c.app_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.app_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('AppAdExtension') - self.app_ad_extension.Type = 'AppAdExtension' - super(BulkAppAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkAppAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.app_ad_extension, 'app_ad_extension') - super(BulkAppAdExtension, self).process_mappings_to_row_values(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 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. - - For more information, see Campaign App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupAppAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level App ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group App Ad Extension record in a bulk file. - - For more information, see Ad Group App Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_call_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_call_ad_extensions.py deleted file mode 100644 index 6e8913a2..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_call_ad_extensions.py +++ /dev/null @@ -1,113 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import * -from .common import _BulkAdExtensionBase -from .common import _BulkCampaignAdExtensionAssociation - -_CallAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('CallAdExtension')) - - -class BulkCallAdExtension(_BulkAdExtensionBase): - """ Represents a call ad extension. - - This class exposes the :attr:`call_ad_extension` property that can be read and written - as fields of the Call Ad Extension record in a bulk file. - - For more information, see Call Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - account_id=None, - ad_extension=None): - if ad_extension and not isinstance(ad_extension, _CallAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'CallAdExtension' - )) - super(BulkCallAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def call_ad_extension(self): - """ The call ad extension. - - see Call Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @call_ad_extension.setter - def call_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.PhoneNumber, - field_to_csv=lambda c: c.call_ad_extension.PhoneNumber, - csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'PhoneNumber', v) - ), - _SimpleBulkMapping( - header=_StringTable.CountryCode, - field_to_csv=lambda c: c.call_ad_extension.CountryCode, - csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'CountryCode', v) - ), - _SimpleBulkMapping( - header=_StringTable.IsCallOnly, - field_to_csv=lambda c: bulk_str(c.call_ad_extension.IsCallOnly), - csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'IsCallOnly', - v.lower() == 'true' if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.IsCallTrackingEnabled, - field_to_csv=lambda c: bulk_str(c.call_ad_extension.IsCallTrackingEnabled), - csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'IsCallTrackingEnabled', - v.lower() == 'true' if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.RequireTollFreeTrackingNumber, - field_to_csv=lambda c: bulk_str(c.call_ad_extension.RequireTollFreeTrackingNumber), - csv_to_field=lambda c, v: setattr(c.call_ad_extension, 'RequireTollFreeTrackingNumber', - v.lower() == 'true' if v else None) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.call_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('CallAdExtension') - self.call_ad_extension.Type = 'CallAdExtension' - super(BulkCallAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkCallAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.call_ad_extension, 'call_ad_extension') - super(BulkCallAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkCallAdExtension._MAPPINGS) - - -class BulkCampaignCallAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level call ad extension. - - This class exposes properties that can be read and written - as fields of the Campaign Call Ad Extension record in a bulk file. - - For more information, see Campaign Call Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_callout_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_callout_ad_extensions.py deleted file mode 100644 index b959254e..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_callout_ad_extensions.py +++ /dev/null @@ -1,125 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -_CalloutAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('CalloutAdExtension')) - - -class BulkCalloutAdExtension(_BulkAdExtensionBase): - """ Represents a callout ad extension. - - This class exposes the :attr:`callout_ad_extension` property that can be read and written - as fields of the Callout Ad Extension record in a bulk file. - - For more information, see Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _CalloutAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'CalloutAdExtension' - )) - super(BulkCalloutAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def callout_ad_extension(self): - """ The callout ad extension. - - see Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @callout_ad_extension.setter - def callout_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.CalloutText, - field_to_csv=lambda c: c.callout_ad_extension.Text, - csv_to_field=lambda c, v: setattr(c.callout_ad_extension, 'Text', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.callout_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('CalloutAdExtension') - self.callout_ad_extension.Type = 'CalloutAdExtension' - super(BulkCalloutAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkCalloutAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.callout_ad_extension, 'callout_ad_extension') - super(BulkCalloutAdExtension, self).process_mappings_to_row_values(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 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. - - For more information, see Campaign Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupCalloutAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level Callout ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Callout Ad Extension record in a bulk file. - - For more information, see Ad Group Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_image_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_image_ad_extensions.py deleted file mode 100644 index 6bf2fd13..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_image_ad_extensions.py +++ /dev/null @@ -1,144 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from bingads.v12.internal.extensions import * -from .common import _BulkAdExtensionBase -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -_ImageAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ImageAdExtension')) - - -class BulkImageAdExtension(_BulkAdExtensionBase): - """ Represents a image ad extension. - - This class exposes the :attr:`image_ad_extension` property that can be read and written - as fields of the Image Ad Extension record in a bulk file. - - For more information, see Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _ImageAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'ImageAdExtension' - )) - super(BulkImageAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def image_ad_extension(self): - """ The image ad extension. - - see Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @image_ad_extension.setter - def image_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.DestinationUrl, - field_to_csv=lambda c: bulk_optional_str(c.image_ad_extension.DestinationUrl, c.image_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'DestinationUrl', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.AltText, - field_to_csv=lambda c: c.image_ad_extension.AlternativeText, - csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'AlternativeText', v) - ), - _SimpleBulkMapping( - header=_StringTable.MediaIds, - #field_to_csv=lambda c: bulk_str(c.image_ad_extension.ImageMediaIds), - field_to_csv=lambda c: field_to_csv_MediaIds(c.image_ad_extension), - #csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'ImageMediaIds', int(v)) - csv_to_field=lambda c, v: csv_to_field_MediaIds(c.image_ad_extension, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.image_ad_extension.FinalUrlSuffix, c.image_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.image_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('ImageAdExtension') - self.image_ad_extension.Type = 'ImageAdExtension' - super(BulkImageAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkImageAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.image_ad_extension, 'image_ad_extension') - super(BulkImageAdExtension, self).process_mappings_to_row_values(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 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. - - For more information, see Campaign Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupImageAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level image ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Image Ad Extension record in a bulk file. - - For more information, see Ad Group Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_location_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_location_ad_extensions.py deleted file mode 100644 index 473e5795..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_location_ad_extensions.py +++ /dev/null @@ -1,242 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import * -from .common import _BulkAdExtensionBase -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -_LocationAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('LocationAdExtension')) - - -class BulkLocationAdExtension(_BulkAdExtensionBase): - """ Represents an location ad extension. - - This class exposes the :attr:`location_ad_extension` property that can be read and written - as fields of the Location Ad Extension record in a bulk file. - - For more information, see Location Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _LocationAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'LocationAdExtension' - )) - super(BulkLocationAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def location_ad_extension(self): - """ The location ad extension. - - see Location Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @location_ad_extension.setter - def location_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.BusinessName, - field_to_csv=lambda c: c.location_ad_extension.CompanyName, - csv_to_field=lambda c, v: setattr(c.location_ad_extension, 'CompanyName', v) - ), - _SimpleBulkMapping( - header=_StringTable.PhoneNumber, - field_to_csv=lambda c: bulk_optional_str(c.location_ad_extension.PhoneNumber, c.location_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.location_ad_extension, 'PhoneNumber', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.GeoCodeStatus, - field_to_csv=lambda c: bulk_str(c.location_ad_extension.GeoCodeStatus), - csv_to_field=lambda c, v: setattr(c.location_ad_extension, 'GeoCodeStatus', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AddressLine1, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( - c, - lambda x: x.StreetAddress - ), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'StreetAddress', v) - ) - ), - _SimpleBulkMapping( - header=_StringTable.AddressLine2, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part( - c, - lambda x: bulk_optional_str(x.StreetAddress2, c.location_ad_extension.Id) - ), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'StreetAddress2', v if v else '') - ) - ), - _SimpleBulkMapping( - header=_StringTable.City, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(c, lambda x: x.CityName), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'CityName', v) - ) - ), - _SimpleBulkMapping( - header=_StringTable.ProvinceName, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(c, lambda x: x.ProvinceName), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'ProvinceName', v) - ) - ), - _SimpleBulkMapping( - header=_StringTable.StateOrProvince, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(c, lambda x: x.ProvinceCode), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'ProvinceCode', v) - ) - ), - - _SimpleBulkMapping( - header=_StringTable.PostalCode, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(c, lambda x: x.PostalCode), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'PostalCode', v) - ) - ), - - _SimpleBulkMapping( - header=_StringTable.CountryCode, - field_to_csv=lambda c: BulkLocationAdExtension.get_address_part(c, lambda x: x.CountryCode), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_address_part( - c, - lambda x: setattr(x, 'CountryCode', v) - ) - ), - _SimpleBulkMapping( - header=_StringTable.Latitude, - field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part( - c, - lambda x: bulk_str( - float(x.LatitudeInMicroDegrees) / 1000000.0 - ) - if x.LatitudeInMicroDegrees is not None else None - ), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_geo_point_part( - c, - lambda x, latitude: setattr(x, 'LatitudeInMicroDegrees', int(round(float(latitude) * 1000000))), - v - ) - ), - _SimpleBulkMapping( - header=_StringTable.Longitude, - field_to_csv=lambda c: BulkLocationAdExtension.get_geo_point_part( - c, - lambda x: bulk_str( - float(x.LongitudeInMicroDegrees) / 1000000.0 - ) - if x.LongitudeInMicroDegrees is not None else None - ), - csv_to_field=lambda c, v: BulkLocationAdExtension.set_geo_point_part( - c, - lambda x, longitude: setattr(x, 'LongitudeInMicroDegrees', int(round(float(longitude) * 1000000))), - v - ) - ), - ] - - @staticmethod - def get_address_part(bulk_ad_extension, get_func): - if bulk_ad_extension.location_ad_extension.Address is not None: - return get_func(bulk_ad_extension.location_ad_extension.Address) - else: - return None - - @staticmethod - def set_address_part(bulk_ad_extension, set_func): - if bulk_ad_extension.location_ad_extension.Address is None: - bulk_ad_extension.location_ad_extension.Address = _CAMPAIGN_OBJECT_FACTORY_V12.create('Address') - set_func(bulk_ad_extension.location_ad_extension.Address) - - @staticmethod - def get_geo_point_part(bulk_ad_extension, get_func): - if bulk_ad_extension.location_ad_extension.GeoPoint is not None: - return get_func(bulk_ad_extension.location_ad_extension.GeoPoint) - else: - return None - - @staticmethod - def set_geo_point_part(bulk_ad_extension, set_func, value): - if not value: - return - if bulk_ad_extension.location_ad_extension.GeoPoint is None: - bulk_ad_extension.location_ad_extension.GeoPoint = _CAMPAIGN_OBJECT_FACTORY_V12.create('GeoPoint') - set_func(bulk_ad_extension.location_ad_extension.GeoPoint, value) - - def process_mappings_from_row_values(self, row_values): - self.location_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.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_V12.create('GeoPoint') - super(BulkLocationAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkLocationAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.location_ad_extension, 'location_ad_extension') - super(BulkLocationAdExtension, self).process_mappings_to_row_values(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 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. - - For more information, see Campaign Location Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass \ No newline at end of file diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_price_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_price_ad_extensions.py deleted file mode 100644 index 8c154793..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_price_ad_extensions.py +++ /dev/null @@ -1,152 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - -_PriceAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('PriceAdExtension')) - - -class BulkPriceAdExtension(_BulkAdExtensionBase): - """ Represents a Price Ad Extension. - - This class exposes the :attr:`price_ad_extension` property that can be read and written - as fields of the Price Ad Extension record in a bulk file. - - For more information, see Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _PriceAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'PriceAdExtension' - )) - super(BulkPriceAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def price_ad_extension(self): - """ The Price Ad Extension. - - see Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @price_ad_extension.setter - def price_ad_extension(self, value): - self._ad_extension = value - - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Language, - field_to_csv=lambda c: c.price_ad_extension.Language, - csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'Language', v) - ), - _SimpleBulkMapping( - header=_StringTable.PriceExtensionType, - field_to_csv=lambda c: c.price_ad_extension.PriceExtensionType, - csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'PriceExtensionType', v) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.price_ad_extension.TrackingUrlTemplate), - csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.price_ad_extension), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.price_ad_extension, v) - ), - _ComplexBulkMapping( - entity_to_csv=lambda c, v: entity_to_csv_PriceTableRows(c.price_ad_extension, v), - csv_to_entity=lambda v, c: csv_to_entity_PriceTableRows(v, c.price_ad_extension) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.price_ad_extension.FinalUrlSuffix, c.price_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.price_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('PriceAdExtension') - self.price_ad_extension.Type = 'PriceAdExtension' - super(BulkPriceAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkPriceAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.price_ad_extension, 'price_ad_extension') - super(BulkPriceAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkPriceAdExtension._MAPPINGS) - - -class BulkAccountPriceAdExtension(_BulkAccountAdExtensionAssociation): - """ Represents an account level Price Ad Extension. - - This class exposes properties that can be read and written - as fields of the Account Price Ad Extension record in a bulk file. - - For more information, see Account Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkCampaignPriceAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level Price Ad Extension. - - This class exposes properties that can be read and written - as fields of the Campaign Price Ad Extension record in a bulk file. - - For more information, see Campaign Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupPriceAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level Price ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Price Ad Extension record in a bulk file. - - For more information, see Ad Group Price Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_review_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_review_ad_extensions.py deleted file mode 100644 index 2a6fc042..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_review_ad_extensions.py +++ /dev/null @@ -1,144 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - -_ReviewAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ReviewAdExtension')) - - -class BulkReviewAdExtension(_BulkAdExtensionBase): - """ Represents a review ad extension. - - This class exposes the :attr:`review_ad_extension` property that can be read and written - as fields of the Review Ad Extension record in a bulk file. - - For more information, see Review Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _ReviewAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'ReviewAdExtension' - )) - super(BulkReviewAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def review_ad_extension(self): - """ The review ad extension. - - see Review Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @review_ad_extension.setter - def review_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.review_ad_extension.Text, - csv_to_field=lambda c, v: setattr(c.review_ad_extension, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.IsExact, - field_to_csv=lambda c: bulk_str(c.review_ad_extension.IsExact), - csv_to_field=lambda c, v: setattr(c.review_ad_extension, 'IsExact', - v.lower() == 'true' if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Source, - field_to_csv=lambda c: c.review_ad_extension.Source, - csv_to_field=lambda c, v: setattr(c.review_ad_extension, 'Source', v) - ), - _SimpleBulkMapping( - header=_StringTable.Url, - field_to_csv=lambda c: c.review_ad_extension.Url, - csv_to_field=lambda c, v: setattr(c.review_ad_extension, 'Url', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.review_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('ReviewAdExtension') - self.review_ad_extension.Type = 'ReviewAdExtension' - super(BulkReviewAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkReviewAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.review_ad_extension, 'review_ad_extension') - super(BulkReviewAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkReviewAdExtension._MAPPINGS) - - -class BulkAccountReviewAdExtension(_BulkAccountAdExtensionAssociation): - """ Represents an account level review ad extension. - - This class exposes properties that can be read and written - as fields of the Account Review Ad Extension record in a bulk file. - - For more information, see Account Review Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - - -class BulkCampaignReviewAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level review ad extension. - - This class exposes properties that can be read and written - as fields of the Campaign Review Ad Extension record in a bulk file. - - For more information, see Campaign Review Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupReviewAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level Review ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Review Ad Extension record in a bulk file. - - For more information, see Ad Group Review Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_sitelink_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_sitelink_ad_extensions.py deleted file mode 100644 index b6e551fa..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_sitelink_ad_extensions.py +++ /dev/null @@ -1,167 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - -_SitelinkAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('SitelinkAdExtension')) - - -class BulkSitelinkAdExtension(_BulkAdExtensionBase): - """ Represents a sitelink ad extension. - - This class exposes the :attr:`sitelink_ad_extension` property that can be read and written - as fields of the Sitelink Ad Extension record in a bulk file. - - For more information, see Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _SitelinkAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'SitelinkAdExtension' - )) - super(BulkSitelinkAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def sitelink_ad_extension(self): - """ The sitelink ad extension. - - see Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_extension - - @sitelink_ad_extension.setter - def sitelink_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.SiteLinkDescription1, - field_to_csv=lambda c: c.sitelink_ad_extension.Description1, - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'Description1', v) - ), - _SimpleBulkMapping( - header=_StringTable.SiteLinkDescription2, - field_to_csv=lambda c: c.sitelink_ad_extension.Description2, - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'Description2', v) - ), - _SimpleBulkMapping( - header=_StringTable.DestinationUrl, - field_to_csv=lambda c: bulk_optional_str(c.sitelink_ad_extension.DestinationUrl, c.sitelink_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'DestinationUrl', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.SiteLinkDisplayText, - field_to_csv=lambda c: c.sitelink_ad_extension.DisplayText, - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'DisplayText', v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.sitelink_ad_extension.FinalUrls, c.sitelink_ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.sitelink_ad_extension.FinalUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalMobileUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.sitelink_ad_extension.FinalMobileUrls, c.sitelink_ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.sitelink_ad_extension.FinalMobileUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.sitelink_ad_extension.TrackingUrlTemplate), - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.sitelink_ad_extension), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.sitelink_ad_extension, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.sitelink_ad_extension.FinalUrlSuffix, c.sitelink_ad_extension.Id), - csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.sitelink_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('SitelinkAdExtension') - self.sitelink_ad_extension.Type = 'SitelinkAdExtension' - super(BulkSitelinkAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkSitelinkAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.sitelink_ad_extension, 'sitelink_ad_extension') - super(BulkSitelinkAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkSitelinkAdExtension._MAPPINGS) - - -class BulkAccountSitelinkAdExtension(_BulkAccountAdExtensionAssociation): - """ Represents an account level sitelink ad extension. - - This class exposes properties that can be read and written - as fields of the Account Sitelink Ad Extension record in a bulk file. - - For more information, see Account Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkCampaignSitelinkAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level sitelink ad extension. - - This class exposes properties that can be read and written - as fields of the Campaign Sitelink Ad Extension record in a bulk file. - - For more information, see Campaign Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupSitelinkAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level Sitelink ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Sitelink Ad Extension record in a bulk file. - - For more information, see Ad Group Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/bulk_structured_snippet_ad_extensions.py b/bingads/v12/bulk/entities/ad_extensions/bulk_structured_snippet_ad_extensions.py deleted file mode 100644 index dc11d6af..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/bulk_structured_snippet_ad_extensions.py +++ /dev/null @@ -1,132 +0,0 @@ -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from .common import _BulkAdExtensionBase -from .common import _BulkAdGroupAdExtensionAssociation -from .common import _BulkCampaignAdExtensionAssociation -from .common import _BulkAccountAdExtensionAssociation - -from bingads.v12.internal.extensions import * - -_StructuredSnippetAdExtension = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('StructuredSnippetAdExtension')) - - -class BulkStructuredSnippetAdExtension(_BulkAdExtensionBase): - """ Represents a structured snippet ad extension. - - This class exposes the :attr:`structured_snippet_ad_extension` property that can be read and written - as fields of the Structured Snippet Ad Extension record in a bulk file. - - For more information, see Structured Snippet Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127 - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, ad_extension=None): - if ad_extension and not isinstance(ad_extension, _StructuredSnippetAdExtension): - raise ValueError('The type of ad_extension is: {0}, should be: {1}'.format( - type(ad_extension), - 'StructuredSnippetAdExtension' - )) - super(BulkStructuredSnippetAdExtension, self).__init__( - account_id=account_id, - ad_extension=ad_extension - ) - - @property - def structured_snippet_ad_extension(self): - """ The structured snippet ad extension. - - see Structured Snippet Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127 - """ - - return self._ad_extension - - @structured_snippet_ad_extension.setter - def structured_snippet_ad_extension(self, value): - self._ad_extension = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.StructuredSnippetHeader, - field_to_csv=lambda c: c.structured_snippet_ad_extension.Header, - csv_to_field=lambda c, v: setattr(c.structured_snippet_ad_extension, 'Header', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.StructuredSnippetValues, - field_to_csv=lambda c: field_to_csv_StructuredSnippetValues(c.structured_snippet_ad_extension), - csv_to_field=lambda c, v: csv_to_field_StructuredSnippetValues(c.structured_snippet_ad_extension, v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.structured_snippet_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create('StructuredSnippetAdExtension') - self.structured_snippet_ad_extension.Type = 'StructuredSnippetAdExtension' - super(BulkStructuredSnippetAdExtension, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkStructuredSnippetAdExtension._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.structured_snippet_ad_extension, 'structured_snippet_ad_extension') - super(BulkStructuredSnippetAdExtension, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkStructuredSnippetAdExtension._MAPPINGS) - - -class BulkAccountStructuredSnippetAdExtension(_BulkAccountAdExtensionAssociation): - """ Represents an account level structured snippet ad extension. - - This class exposes properties that can be read and written - as fields of the Account Structured Snippet Ad Extension record in a bulk file. - - For more information, see Account Structured Snippet Extension at https://go.microsoft.com/fwlink/?linkid=846127 - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkCampaignStructuredSnippetAdExtension(_BulkCampaignAdExtensionAssociation): - """ Represents a campaign level structured snippet ad extension. - - This class exposes properties that can be read and written - as fields of the Campaign Structured Snippet Ad Extension record in a bulk file. - - For more information, see Campaign Structured Snippet Extension at https://go.microsoft.com/fwlink/?linkid=846127 - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass - -class BulkAdGroupStructuredSnippetAdExtension(_BulkAdGroupAdExtensionAssociation): - """ Represents an ad group level structured snippet ad extension. - - This class exposes properties that can be read and written - as fields of the Ad Group Structured Snippet Ad Extension record in a bulk file. - - For more information, see Ad Group Structured Snippet Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127 - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - pass diff --git a/bingads/v12/bulk/entities/ad_extensions/common.py b/bingads/v12/bulk/entities/ad_extensions/common.py deleted file mode 100644 index 7aef3e0e..00000000 --- a/bingads/v12/bulk/entities/ad_extensions/common.py +++ /dev/null @@ -1,394 +0,0 @@ -from bingads.v12.bulk.entities.common import PerformanceData - -from bingads.v12.internal.bulk.entities.bulk_entity_identifier import _BulkEntityIdentifier -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.extensions import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -Date = _CAMPAIGN_OBJECT_FACTORY_V12.create('Date') - -class _BulkAdExtensionBase(_SingleRecordBulkEntity): - """ This class provides properties that are shared by all bulk ad extension classes. - - *See also:* - - * :class:`.BulkCallAdExtension` - * :class:`.BulkImageAdExtension` - * :class:`.BulkLocationAdExtension` - * :class:`.BulkSiteLinkAdExtension` - """ - - def __init__(self, account_id=None, ad_extension=None): - super(_BulkAdExtensionBase, self).__init__() - - self._account_id = account_id - self._ad_extension = ad_extension - - @property - def account_id(self): - """ The ad extension's parent account identifier. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._account_id - - @account_id.setter - def account_id(self, account_id): - self._account_id = account_id - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: bulk_str(c._ad_extension.Status), - csv_to_field=lambda c, v: setattr(c._ad_extension, 'Status', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c._ad_extension.Id), - csv_to_field=lambda c, v: setattr(c._ad_extension, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Version, - field_to_csv=lambda c: bulk_str(c._ad_extension.Version), - csv_to_field=lambda c, v: setattr(c._ad_extension, 'Version', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.account_id), - csv_to_field=lambda c, v: setattr(c, 'account_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.StartDate, - field_to_csv=lambda c: field_to_csv_SchedulingStartDate(c._ad_extension.Scheduling, c._ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'StartDate', v) - ), - _SimpleBulkMapping( - header=_StringTable.EndDate, - field_to_csv=lambda c: field_to_csv_SchedulingEndDate(c._ad_extension.Scheduling, c._ad_extension.Id), - csv_to_field = lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'EndDate', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdSchedule, - field_to_csv=lambda c: field_to_csv_AdSchedule(c._ad_extension.Scheduling, c._ad_extension.Id), - csv_to_field=lambda c, v: csv_to_field_AdSchedule(c._ad_extension.Scheduling, v) - ), - _SimpleBulkMapping( - header=_StringTable.UseSearcherTimeZone, - field_to_csv=lambda c: field_to_csv_UseSearcherTimeZone(c._ad_extension.Scheduling, c._ad_extension.Id), - csv_to_field=lambda c, v: setattr(c._ad_extension.Scheduling, 'UseSearcherTimeZone', parse_bool(v)) - ), - _SimpleBulkMapping( - header=_StringTable.DevicePreference, - field_to_csv=lambda c: bulk_device_preference_str(c._ad_extension.DevicePreference), - csv_to_field=lambda c, v: setattr(c._ad_extension, 'DevicePreference', parse_device_preference(v)) - ), - ] - - def process_mappings_from_row_values(self, row_values): - row_values.convert_to_entity(self, _BulkAdExtensionBase._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, _BulkAdExtensionBase._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(_BulkAdExtensionBase, self).read_additional_data(stream_reader) - - -class _BulkAdExtensionAssociation(_SingleRecordBulkEntity): - """ This class provides properties that are shared by all bulk ad extension association classes. - - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - def __init__(self, - ad_extension_id_to_entity_id_association=None, - status=None, - editorial_status=None): - super(_BulkAdExtensionAssociation, self).__init__() - - self._status = status - self._ad_extension_id_to_entity_id_association = ad_extension_id_to_entity_id_association - self._editorial_status = editorial_status - self._performance_data = None - - @property - def ad_extension_id_to_entity_id_association(self): - """ Defines an association relationship between an ad extension and a supported entity, for example a campaign or ad group. - - :rtype: AdExtensionIdToEntityIdAssociation - """ - - return self._ad_extension_id_to_entity_id_association - - @ad_extension_id_to_entity_id_association.setter - def ad_extension_id_to_entity_id_association(self, value): - self._ad_extension_id_to_entity_id_association = value - - @property - def status(self): - """ The status of the ad extension association. - - The value is Active if the EntityId and AdExtensionId are associated. The value is Deleted if the association is removed. - Corresponds to the 'Status' field in the bulk file. - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def editorial_status(self): - """ The editorial status of the ad extension and associated entity. - - For more information, see AdExtensionEditorialStatus at https://go.microsoft.com/fwlink/?linkid=846127. - Corresponds to the 'Editorial Status' field in the bulk file. - - :rtype: str - """ - - return self._editorial_status - - @editorial_status.setter - def editorial_status(self, editorial_status): - self._editorial_status = editorial_status - - @property - def performance_data(self): - return self._performance_data - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.AdExtensionId), - csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'AdExtensionId', int(v)) - ), - _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.ParentId, - field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.EntityId), - csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'EntityId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialStatus, - field_to_csv=lambda c: c.editorial_status, - csv_to_field=lambda c, v: setattr(c, '_editorial_status', v if v else None) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self._ad_extension_id_to_entity_id_association = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdExtensionIdToEntityIdAssociation') - row_values.convert_to_entity(self, _BulkAdExtensionAssociation._MAPPINGS) - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null( - self._ad_extension_id_to_entity_id_association, - 'ad_extension_id_to_entity_id_association' - ) - self.convert_to_values(row_values, _BulkAdExtensionAssociation._MAPPINGS) - if not exclude_readonly_data: - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) - - def read_additional_data(self, stream_reader): - super(_BulkAdExtensionAssociation, self).read_additional_data(stream_reader) - - -class _BulkAccountAdExtensionAssociation(_BulkAdExtensionAssociation): - """ This abstract class provides properties that are shared by all bulk account ad extension association classes. """ - - def __init__(self, - ad_extension_id_to_entity_id_association=None, - status=None, - editorial_status=None): - super(_BulkAccountAdExtensionAssociation, self).__init__( - ad_extension_id_to_entity_id_association, - status, - editorial_status, - ) - - -class _BulkCampaignAdExtensionAssociation(_BulkAdExtensionAssociation): - """ This abstract class provides properties that are shared by all bulk campaign ad extension association classes. """ - - def __init__(self, - ad_extension_id_to_entity_id_association=None, - status=None, - editorial_status=None): - super(_BulkCampaignAdExtensionAssociation, self).__init__( - ad_extension_id_to_entity_id_association, - status, - editorial_status, - ) - self._campaign_name = None - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, '_campaign_name', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - super(_BulkCampaignAdExtensionAssociation, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, _BulkCampaignAdExtensionAssociation._MAPPINGS) - - @property - def campaign_name(self): - """ The name of the campaign containing the ad group that the ad extension is associated. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - -class _BulkAdGroupAdExtensionAssociation(_BulkAdExtensionAssociation): - """ This abstract class provides properties that are shared by all bulk ad group ad extension association classes. """ - - def __init__(self, - ad_extension_id_to_entity_id_association=None, - status=None, - editorial_status=None): - super(_BulkAdGroupAdExtensionAssociation, self).__init__( - ad_extension_id_to_entity_id_association, - status, - editorial_status, - ) - self._ad_group_name = None - self._campaign_name = None - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, '_campaign_name', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - super(_BulkAdGroupAdExtensionAssociation, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, _BulkAdGroupAdExtensionAssociation._MAPPINGS) - - @property - def ad_group_name(self): - """ The name of the ad group that the ad extension is associated. - - Corresponds to the 'AdGroup' field in the bulk file. - - :rtype str - """ - - return self._ad_group_name - - @property - def campaign_name(self): - """ The name of the campaign containing the ad group that the ad extension is associated. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - -class _BulkAdExtensionIdentifier(_BulkEntityIdentifier): - def __init__(self, - account_id=None, - ad_extension_id=None, - status=None, - version=None): - super(_BulkAdExtensionIdentifier, self).__init__() - - self._account_id = account_id - self._ad_extension_id = ad_extension_id - self._status = status - self._version = version - - @property - def account_id(self): - return self._account_id - - @account_id.setter - def account_id(self, account_id): - self._account_id = account_id - - @property - def ad_extension_id(self): - return self._ad_extension_id - - @ad_extension_id.setter - def ad_extension_id(self, ad_extension_id): - self._ad_extension_id = ad_extension_id - - @property - def status(self): - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def version(self): - return self._version - - @version.setter - def version(self, version): - self._version = version - - _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: bulk_str(c.ad_extension_id), - csv_to_field=lambda c, v: setattr(c, 'ad_extension_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Version, - field_to_csv=lambda c: bulk_str(c.version), - csv_to_field=lambda c, v: setattr(c, 'version', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.account_id), - csv_to_field=lambda c, v: setattr(c, 'account_id', int(v) if v else None) - ), - ] - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, _BulkAdExtensionIdentifier._MAPPINGS) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, _BulkAdExtensionIdentifier._MAPPINGS) - - def __eq__(self, other): - raise NotImplementedError() - - @property - def is_delete_row(self): - return self._status == 'Deleted' diff --git a/bingads/v12/bulk/entities/audiences/__init__.py b/bingads/v12/bulk/entities/audiences/__init__.py deleted file mode 100644 index 03fd028c..00000000 --- a/bingads/v12/bulk/entities/audiences/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .bulk_remarketing_list import * -from .bulk_custom_audience import * -from .bulk_ad_group_custom_audience_association import * -from .bulk_in_market_audience import * -from .bulk_ad_group_in_market_audience_association import * -from .bulk_ad_group_product_audience_association import * -from .bulk_ad_group_negative_product_audience_association import * -from .bulk_ad_group_negative_in_market_audience_association import * -from .bulk_ad_group_negative_custom_audience_association import * -from .bulk_ad_group_negative_remarketing_list_association import * -from .bulk_ad_group_negative_similar_remarketing_list_association import * -from .bulk_ad_group_remarketing_list_association import * -from .bulk_product_audience import * -from .bulk_similar_remarketing_list import * -from .bulk_ad_group_similar_remarketing_list_association import * -from .bulk_ad_group_audience_association import * -from .bulk_ad_group_negative_audience_association import * -from .bulk_campaign_audience_association import * -from .bulk_campaign_custom_audience_association import * -from .bulk_campaign_in_market_audience_association import * -from .bulk_campaign_product_audience_association import * -from .bulk_campaign_remarketing_list_association import * -from .bulk_campaign_similar_remarketing_list_association import * -from .bulk_campaign_negative_audience_association import * -from .bulk_campaign_negative_remarketing_list_association import * -from .bulk_campaign_negative_custom_audience_association import * -from .bulk_campaign_negative_in_market_audience_association import * -from .bulk_campaign_negative_product_audience_association import * -from .bulk_campaign_negative_similar_remarketing_list_association import * \ No newline at end of file diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_audience_association.py deleted file mode 100644 index 33f7128c..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_audience_association.py +++ /dev/null @@ -1,148 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkAdGroupAudienceAssociation(_SingleRecordBulkEntity): - """ Base class for all Ad Group Audience Association subclasses that can be read or written in a bulk file. - - *See also:* - - * :class:`.BulkAdGroupCustomAudienceAssociation` - * :class:`.BulkAdGroupInMarketAudienceAssociation` - * :class:`.BulkAdGroupProductAudienceAssociation` - * :class:`.BulkAdGroupRemarketingListAssociation` - * :class:`.BulkAdGroupSimilarRemarketingListAssociation` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, - audience_name=None): - super(BulkAdGroupAudienceAssociation, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._audience_name = audience_name - self._performance_data = None - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: c.audience_name, - csv_to_field=lambda c, v: setattr(c, 'audience_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceId, - field_to_csv=lambda c: field_to_csv_CriterionAudienceId(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(c.biddable_ad_group_criterion, int(v) if v else None) - ), - ] - - @property - def biddable_ad_group_criterion(self): - """ Defines a Biddable 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 - - @property - def campaign_name(self): - """ Defines the name of the Campaign. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ Defines the name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def audience_name(self): - """ Defines the name of the Audience - - :rtype: str - """ - - return self._audience_name - - @audience_name.setter - def audience_name(self, audience_name): - self._audience_name = audience_name - - @property - def performance_data(self): - return self._performance_data - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AudienceCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'AudienceCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupAudienceAssociation._MAPPINGS) - - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupAudienceAssociation._MAPPINGS) - - PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupAudienceAssociation, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_custom_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_custom_audience_association.py deleted file mode 100644 index 67da4c96..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_custom_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_audience_association import BulkAdGroupAudienceAssociation - -class BulkAdGroupCustomAudienceAssociation(BulkAdGroupAudienceAssociation): - """ Represents an Ad Group Custom Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group Custom Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_in_market_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_in_market_audience_association.py deleted file mode 100644 index b960f146..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_in_market_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_audience_association import BulkAdGroupAudienceAssociation - -class BulkAdGroupInMarketAudienceAssociation(BulkAdGroupAudienceAssociation): - """ Represents an Ad Group In Market Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group In Market Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_audience_association.py deleted file mode 100644 index 225a41ee..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_audience_association.py +++ /dev/null @@ -1,132 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkAdGroupNegativeAudienceAssociation(_SingleRecordBulkEntity): - """ Base class for all Ad Group Negative Audience Association subclasses that can be read or written in a bulk file. - - *See also:* - - * :class:`.BulkAdGroupNegativeCustomAudienceAssociation` - * :class:`.BulkAdGroupNegativeInMarketAudienceAssociation` - * :class:`.BulkAdGroupNegativeProductAudienceAssociation` - * :class:`.BulkAdGroupNegativeRemarketingListAssociation` - * :class:`.BulkAdGroupNegativeSimilarRemarketingListAssociation` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, - audience_name=None): - super(BulkAdGroupNegativeAudienceAssociation, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._audience_name = audience_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: c.audience_name, - csv_to_field=lambda c, v: setattr(c, 'audience_name', v) - ), - _SimpleBulkMapping( - _StringTable.AudienceId, - field_to_csv=lambda c: field_to_csv_CriterionAudienceId(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(c.negative_ad_group_criterion, int(v) if v else None) - ), - ] - - @property - def negative_ad_group_criterion(self): - """ Defines a Negative Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - @property - def campaign_name(self): - """ Defines the name of the Campaign. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ Defines the name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def audience_name(self): - """ Defines the name of the Audience - - :rtype: str - """ - - return self._audience_name - - @audience_name.setter - def audience_name(self, audience_name): - self._audience_name = audience_name - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AudienceCriterion') - self._negative_ad_group_criterion.Criterion.Type = 'AudienceCriterion' - row_values.convert_to_entity(self, BulkAdGroupNegativeAudienceAssociation._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeAudienceAssociation._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeAudienceAssociation, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_custom_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_custom_audience_association.py deleted file mode 100644 index b85f38e2..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_custom_audience_association.py +++ /dev/null @@ -1,15 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_negative_audience_association import * - - -class BulkAdGroupNegativeCustomAudienceAssociation(BulkAdGroupNegativeAudienceAssociation): - """ Represents an Ad Group Negative Custom Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group Negative Custom Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_in_market_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_in_market_audience_association.py deleted file mode 100644 index 361750e1..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_in_market_audience_association.py +++ /dev/null @@ -1,15 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_negative_audience_association import * - - -class BulkAdGroupNegativeInMarketAudienceAssociation(BulkAdGroupNegativeAudienceAssociation): - """ Represents an Ad Group Negative In Market Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group Negative In Market Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_product_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_product_audience_association.py deleted file mode 100644 index 825c1f6f..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_product_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_negative_audience_association import * - -class BulkAdGroupNegativeProductAudienceAssociation(BulkAdGroupNegativeAudienceAssociation): - """ Represents an Ad Group Negative Product Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group Negative Product Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_remarketing_list_association.py deleted file mode 100644 index 252e4bce..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_negative_audience_association import * - -class BulkAdGroupNegativeRemarketingListAssociation(BulkAdGroupNegativeAudienceAssociation): - """ Represents an Ad Group Negative Remarketing List Association that can be read or written in a bulk file. - - For more information, see Ad Group Negative Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_similar_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_similar_remarketing_list_association.py deleted file mode 100644 index a95fd35a..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_negative_similar_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_negative_audience_association import * - -class BulkAdGroupNegativeSimilarRemarketingListAssociation(BulkAdGroupNegativeAudienceAssociation): - """ Represents an Ad Group Negative Similar Remarketing List Association that can be read or written in a bulk file. - - For more information, see Ad Group Negative Similar Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_product_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_product_audience_association.py deleted file mode 100644 index 0babc943..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_product_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_audience_association import BulkAdGroupAudienceAssociation - -class BulkAdGroupProductAudienceAssociation(BulkAdGroupAudienceAssociation): - """ Represents an Ad Group Product Audience Association that can be read or written in a bulk file. - - For more information, see Ad Group Product Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_remarketing_list_association.py deleted file mode 100644 index 586a481e..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_audience_association import BulkAdGroupAudienceAssociation - -class BulkAdGroupRemarketingListAssociation(BulkAdGroupAudienceAssociation): - """ Represents an Ad Group Remarketing List Association that can be read or written in a bulk file. - - For more information, see Ad Group Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_ad_group_similar_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_ad_group_similar_remarketing_list_association.py deleted file mode 100644 index b2f0972a..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_ad_group_similar_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_ad_group_audience_association import BulkAdGroupAudienceAssociation - -class BulkAdGroupSimilarRemarketingListAssociation(BulkAdGroupAudienceAssociation): - """ Represents an Ad Group Similar Remarketing List Association that can be read or written in a bulk file. - - For more information, see Ad Group Similar Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_audience_association.py deleted file mode 100644 index d7ad1cff..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_audience_association.py +++ /dev/null @@ -1,128 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkCampaignAudienceAssociation(_SingleRecordBulkEntity): - """ Base class for all Campaign Audience Association subclasses that can be read or written in a bulk file. - - *See also:* - - * :class:`.BulkCampaignCustomAudienceAssociation` - * :class:`.BulkCampaignInMarketAudienceAssociation` - * :class:`.BulkCampaignProductAudienceAssociation` - * :class:`.BulkCampaignRemarketingListAssociation` - * :class:`.BulkCampaignSimilarRemarketingListAssociation` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, - audience_name=None): - super(BulkCampaignAudienceAssociation, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - self._audience_name = audience_name - self._performance_data = None - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: c.audience_name, - csv_to_field=lambda c, v: setattr(c, 'audience_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceId, - field_to_csv=lambda c: field_to_csv_CriterionAudienceId(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(c.biddable_campaign_criterion, int(v) if v else None) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Biddable Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ Defines the name of the Campaign. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def audience_name(self): - """ Defines the name of the Audience - - :rtype: str - """ - - return self._audience_name - - @audience_name.setter - def audience_name(self, audience_name): - self._audience_name = audience_name - - @property - def performance_data(self): - return self._performance_data - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AudienceCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'AudienceCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignAudienceAssociation._MAPPINGS) - - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignAudienceAssociation._MAPPINGS) - - PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values) - - def read_additional_data(self, stream_reader): - super(BulkCampaignAudienceAssociation, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_custom_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_custom_audience_association.py deleted file mode 100644 index 053da5fb..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_custom_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_audience_association import BulkCampaignAudienceAssociation - -class BulkCampaignCustomAudienceAssociation(BulkCampaignAudienceAssociation): - """ Represents an Campaign Custom Audience Association that can be read or written in a bulk file. - - For more information, see Campaign Custom Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_in_market_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_in_market_audience_association.py deleted file mode 100644 index c06088d3..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_in_market_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_audience_association import BulkCampaignAudienceAssociation - -class BulkCampaignInMarketAudienceAssociation(BulkCampaignAudienceAssociation): - """ Represents an Campaign In Market Audience Association that can be read or written in a bulk file. - - For more information, see Campaign In Market Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_audience_association.py deleted file mode 100644 index 809e6773..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_audience_association.py +++ /dev/null @@ -1,112 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkCampaignNegativeAudienceAssociation(_SingleRecordBulkEntity): - """ Base class for all Campaign Negative Audience Association subclasses that can be read or written in a bulk file. - - *See also:* - - * :class:`.BulkCampaignNegativeCustomAudienceAssociation` - * :class:`.BulkCampaignNegativeInMarketAudienceAssociation` - * :class:`.BulkCampaignNegativeProductAudienceAssociation` - * :class:`.BulkCampaignNegativeRemarketingListAssociation` - * :class:`.BulkCampaignNegativeSimilarRemarketingListAssociation` - """ - - def __init__(self, - negative_campaign_criterion=None, - campaign_name=None, - audience_name=None): - super(BulkCampaignNegativeAudienceAssociation, self).__init__() - - self._negative_campaign_criterion = negative_campaign_criterion - self._campaign_name = campaign_name - self._audience_name = audience_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: c.audience_name, - csv_to_field=lambda c, v: setattr(c, 'audience_name', v) - ), - _SimpleBulkMapping( - _StringTable.AudienceId, - field_to_csv=lambda c: field_to_csv_CriterionAudienceId(c.negative_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(c.negative_campaign_criterion, int(v) if v else None) - ), - ] - - @property - def negative_campaign_criterion(self): - """ Defines a Negative Campaign Criterion """ - - return self._negative_campaign_criterion - - @negative_campaign_criterion.setter - def negative_campaign_criterion(self, negative_campaign_criterion): - self._negative_campaign_criterion = negative_campaign_criterion - - @property - def campaign_name(self): - """ Defines the name of the Campaign. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def audience_name(self): - """ Defines the name of the Audience - - :rtype: str - """ - - return self._audience_name - - @audience_name.setter - def audience_name(self, audience_name): - self._audience_name = audience_name - - def process_mappings_from_row_values(self, row_values): - self._negative_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeCampaignCriterion') - self._negative_campaign_criterion.Type = 'NegativeCampaignCriterion' - self._negative_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AudienceCriterion') - self._negative_campaign_criterion.Criterion.Type = 'AudienceCriterion' - row_values.convert_to_entity(self, BulkCampaignNegativeAudienceAssociation._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_campaign_criterion, 'negative_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignNegativeAudienceAssociation._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignNegativeAudienceAssociation, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_custom_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_custom_audience_association.py deleted file mode 100644 index af6e6727..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_custom_audience_association.py +++ /dev/null @@ -1,15 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_negative_audience_association import * - - -class BulkCampaignNegativeCustomAudienceAssociation(BulkCampaignNegativeAudienceAssociation): - """ Represents an Campaign Negative Custom Audience Association that can be read or written in a bulk file. - - For more information, see Campaign Negative Custom Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_in_market_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_in_market_audience_association.py deleted file mode 100644 index 3dd00473..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_in_market_audience_association.py +++ /dev/null @@ -1,15 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_negative_audience_association import * - - -class BulkCampaignNegativeInMarketAudienceAssociation(BulkCampaignNegativeAudienceAssociation): - """ Represents an Campaign Negative In Market Audience Association that can be read or written in a bulk file. - - For more information, see Campaign Negative In Market Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_product_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_product_audience_association.py deleted file mode 100644 index 6afe4873..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_product_audience_association.py +++ /dev/null @@ -1,15 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_negative_audience_association import * - - -class BulkCampaignNegativeProductAudienceAssociation(BulkCampaignNegativeAudienceAssociation): - """ Represents an Campaign Negative Product Audience Association that can be read or written in a bulk file. - - For more information, see Campaign Negative Product Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_remarketing_list_association.py deleted file mode 100644 index 25903881..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_negative_audience_association import * - -class BulkCampaignNegativeRemarketingListAssociation(BulkCampaignNegativeAudienceAssociation): - """ Represents an Campaign Negative Remarketing List Association that can be read or written in a bulk file. - - For more information, see Campaign Negative Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_similar_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_similar_remarketing_list_association.py deleted file mode 100644 index 54e0f7fb..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_negative_similar_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_negative_audience_association import * - -class BulkCampaignNegativeSimilarRemarketingListAssociation(BulkCampaignNegativeAudienceAssociation): - """ Represents an Campaign Negative Similar Remarketing List Association that can be read or written in a bulk file. - - For more information, see Campaign Negative Similar Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_product_audience_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_product_audience_association.py deleted file mode 100644 index 110c6945..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_product_audience_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_audience_association import BulkCampaignAudienceAssociation - -class BulkCampaignProductAudienceAssociation(BulkCampaignAudienceAssociation): - """ Represents an Campaign Product Audience Association that can be read or written in a bulk file. - - For more information, see Campaign Product Audience Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_remarketing_list_association.py deleted file mode 100644 index 72a63a75..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_audience_association import BulkCampaignAudienceAssociation - -class BulkCampaignRemarketingListAssociation(BulkCampaignAudienceAssociation): - """ Represents an Campaign Remarketing List Association that can be read or written in a bulk file. - - For more information, see Campaign Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_campaign_similar_remarketing_list_association.py b/bingads/v12/bulk/entities/audiences/bulk_campaign_similar_remarketing_list_association.py deleted file mode 100644 index d75db901..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_campaign_similar_remarketing_list_association.py +++ /dev/null @@ -1,14 +0,0 @@ -from bingads.v12.bulk.entities.audiences.bulk_campaign_audience_association import BulkCampaignAudienceAssociation - -class BulkCampaignSimilarRemarketingListAssociation(BulkCampaignAudienceAssociation): - """ Represents an Campaign Similar Remarketing List Association that can be read or written in a bulk file. - - For more information, see Campaign Similar Remarketing List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ diff --git a/bingads/v12/bulk/entities/audiences/bulk_custom_audience.py b/bingads/v12/bulk/entities/audiences/bulk_custom_audience.py deleted file mode 100644 index 8ac23f07..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_custom_audience.py +++ /dev/null @@ -1,118 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCustomAudience(_SingleRecordBulkEntity): - """ Represents a Custom Audience that can be read or written in a bulk file. - - This class exposes the :attr:`custom_audience` property that can be read and written as fields of the - Custom Audience record in a bulk file. - - For more information, see Custom Audience at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - custom_audience=None, - status=None,): - super(BulkCustomAudience, self).__init__() - - self._custom_audience = custom_audience - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.custom_audience.Id), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.custom_audience.ParentId), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'ParentId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.custom_audience.Name), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'Name', v) - ), - _SimpleBulkMapping( - _StringTable.Description, - field_to_csv=lambda c: bulk_str(c.custom_audience.Description), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'Description', v) - ), - _SimpleBulkMapping( - _StringTable.MembershipDuration, - field_to_csv=lambda c: bulk_str(c.custom_audience.MembershipDuration), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'MembershipDuration', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Scope, - field_to_csv=lambda c: bulk_str(c.custom_audience.Scope), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'Scope', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceSearchSize, - field_to_csv=lambda c: bulk_str(c.custom_audience.SearchSize), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'SearchSize', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AudienceNetworkSize, - field_to_csv=lambda c: bulk_str(c.custom_audience.AudienceNetworkSize), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'AudienceNetworkSize', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SupportedCampaignTypes, - field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(c.custom_audience.SupportedCampaignTypes), - csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(c.custom_audience.SupportedCampaignTypes, v) - ), - ] - - @property - def custom_audience(self): - """ Defines a Custom Audience """ - - return self._custom_audience - - @custom_audience.setter - def custom_audience(self, custom_audience): - self._custom_audience = custom_audience - - @property - def status(self): - """ The status of the Custom Audience - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.custom_audience, 'custom_audience') - self.convert_to_values(row_values, BulkCustomAudience._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._custom_audience = _CAMPAIGN_OBJECT_FACTORY_V12.create('CustomAudience') - row_values.convert_to_entity(self, BulkCustomAudience._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCustomAudience, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_in_market_audience.py b/bingads/v12/bulk/entities/audiences/bulk_in_market_audience.py deleted file mode 100644 index 73b6936e..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_in_market_audience.py +++ /dev/null @@ -1,118 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkInMarketAudience(_SingleRecordBulkEntity): - """ Represents an In Market Audience that can be read or written in a bulk file. - - This class exposes the :attr:`in_market_audience` property that can be read and written as fields of the - In Market Audience record in a bulk file. - - For more information, see In Market Audience at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - in_market_audience=None, - status=None,): - super(BulkInMarketAudience, self).__init__() - - self._in_market_audience = in_market_audience - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.in_market_audience.Id), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.in_market_audience.ParentId), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'ParentId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.in_market_audience.Name), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'Name', v) - ), - _SimpleBulkMapping( - _StringTable.Description, - field_to_csv=lambda c: bulk_str(c.in_market_audience.Description), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'Description', v) - ), - _SimpleBulkMapping( - _StringTable.MembershipDuration, - field_to_csv=lambda c: bulk_str(c.in_market_audience.MembershipDuration), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'MembershipDuration', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Scope, - field_to_csv=lambda c: bulk_str(c.in_market_audience.Scope), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'Scope', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceSearchSize, - field_to_csv=lambda c: bulk_str(c.in_market_audience.SearchSize), - csv_to_field=lambda c, v: setattr(c.in_market_audience, 'SearchSize', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AudienceNetworkSize, - field_to_csv=lambda c: bulk_str(c.custom_audience.AudienceNetworkSize), - csv_to_field=lambda c, v: setattr(c.custom_audience, 'AudienceNetworkSize', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SupportedCampaignTypes, - field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(c.custom_audience.SupportedCampaignTypes), - csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(c.custom_audience.SupportedCampaignTypes, v) - ), - ] - - @property - def in_market_audience(self): - """ Defines an In Market Audience """ - - return self._in_market_audience - - @in_market_audience.setter - def in_market_audience(self, in_market_audience): - self._in_market_audience = in_market_audience - - @property - def status(self): - """ The status of the In Market Audience - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.in_market_audience, 'in_market_audience') - self.convert_to_values(row_values, BulkInMarketAudience._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._in_market_audience = _CAMPAIGN_OBJECT_FACTORY_V12.create('InMarketAudience') - row_values.convert_to_entity(self, BulkInMarketAudience._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkInMarketAudience, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_product_audience.py b/bingads/v12/bulk/entities/audiences/bulk_product_audience.py deleted file mode 100644 index 80d96c0d..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_product_audience.py +++ /dev/null @@ -1,128 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkProductAudience(_SingleRecordBulkEntity): - """ Represents a Product Audience that can be read or written in a bulk file. - - This class exposes the :attr:`product_audience` property that can be read and written as fields of the - Product Audience record in a bulk file. - - For more information, see Product Audience at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - product_audience=None, - status=None,): - super(BulkProductAudience, self).__init__() - - self._product_audience = product_audience - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.product_audience.Id), - csv_to_field=lambda c, v: setattr(c.product_audience, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.product_audience.ParentId), - csv_to_field=lambda c, v: setattr(c.product_audience, 'ParentId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.product_audience.Name), - csv_to_field=lambda c, v: setattr(c.product_audience, 'Name', v) - ), - _SimpleBulkMapping( - _StringTable.Description, - field_to_csv=lambda c: bulk_str(c.product_audience.Description), - csv_to_field=lambda c, v: setattr(c.product_audience, 'Description', v) - ), - _SimpleBulkMapping( - _StringTable.MembershipDuration, - field_to_csv=lambda c: bulk_str(c.product_audience.MembershipDuration), - csv_to_field=lambda c, v: setattr(c.product_audience, 'MembershipDuration', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Scope, - field_to_csv=lambda c: bulk_str(c.product_audience.Scope), - csv_to_field=lambda c, v: setattr(c.product_audience, 'Scope', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceSearchSize, - field_to_csv=lambda c: bulk_str(c.product_audience.SearchSize), - csv_to_field=lambda c, v: setattr(c.product_audience, 'SearchSize', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AudienceNetworkSize, - field_to_csv=lambda c: bulk_str(c.product_audience.AudienceNetworkSize), - csv_to_field=lambda c, v: setattr(c.product_audience, 'AudienceNetworkSize', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SupportedCampaignTypes, - field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(c.product_audience.SupportedCampaignTypes), - csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(c.product_audience.SupportedCampaignTypes, v) - ), - _SimpleBulkMapping( - _StringTable.TagId, - field_to_csv=lambda c: bulk_str(c.product_audience.TagId), - csv_to_field=lambda c, v: setattr(c.product_audience, 'TagId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.product_audience.ProductAudienceType), - csv_to_field=lambda c, v: setattr(c.product_audience, 'ProductAudienceType', v) - ), - ] - - @property - def product_audience(self): - """ Defines a Product Audience """ - - return self._product_audience - - @product_audience.setter - def product_audience(self, product_audience): - self._product_audience = product_audience - - @property - def status(self): - """ The status of the Product Audience - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.product_audience, 'product_audience') - self.convert_to_values(row_values, BulkProductAudience._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._product_audience = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductAudience') - row_values.convert_to_entity(self, BulkProductAudience._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkProductAudience, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_remarketing_list.py b/bingads/v12/bulk/entities/audiences/bulk_remarketing_list.py deleted file mode 100644 index 5bb067cd..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_remarketing_list.py +++ /dev/null @@ -1,128 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkRemarketingList(_SingleRecordBulkEntity): - """ Represents an Remarketing List that can be read or written in a bulk file. - - This class exposes the :attr:`remarketing_list` property that can be read and written as fields of the - Remarketing List record in a bulk file. - - For more information, see Remarketing List at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - remarketing_list=None, - status=None,): - super(BulkRemarketingList, self).__init__() - - self._remarketing_list = remarketing_list - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.remarketing_list.Id), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.remarketing_list.ParentId), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'ParentId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.remarketing_list.Name), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Name', v) - ), - _SimpleBulkMapping( - _StringTable.Description, - field_to_csv=lambda c: bulk_str(c.remarketing_list.Description), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Description', v) - ), - _SimpleBulkMapping( - _StringTable.MembershipDuration, - field_to_csv=lambda c: bulk_str(c.remarketing_list.MembershipDuration), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'MembershipDuration', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Scope, - field_to_csv=lambda c: bulk_str(c.remarketing_list.Scope), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Scope', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.TagId, - field_to_csv=lambda c: bulk_str(c.remarketing_list.TagId), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'TagId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.RemarketingRule, - field_to_csv=lambda c: field_to_csv_RemarketingRule(c.remarketing_list), - csv_to_field=lambda c, v: csv_to_field_RemarketingRule(c.remarketing_list, v) - ), - _SimpleBulkMapping( - _StringTable.AudienceSearchSize, - field_to_csv=lambda c: bulk_str(c.remarketing_list.SearchSize), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'SearchSize', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AudienceNetworkSize, - field_to_csv=lambda c: bulk_str(c.remarketing_list.AudienceNetworkSize), - csv_to_field=lambda c, v: setattr(c.remarketing_list, 'AudienceNetworkSize', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SupportedCampaignTypes, - field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(c.remarketing_list.SupportedCampaignTypes), - csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(c.remarketing_list.SupportedCampaignTypes, v) - ), - ] - - @property - def remarketing_list(self): - """ Defines a Remarketing List """ - - return self._remarketing_list - - @remarketing_list.setter - def remarketing_list(self, remarketing_list): - self._remarketing_list = remarketing_list - - @property - def status(self): - """ The status of the Remarketing List - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.remarketing_list, 'remarketing_list') - self.convert_to_values(row_values, BulkRemarketingList._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._remarketing_list = _CAMPAIGN_OBJECT_FACTORY_V12.create('RemarketingList') - row_values.convert_to_entity(self, BulkRemarketingList._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkRemarketingList, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/audiences/bulk_similar_remarketing_list.py b/bingads/v12/bulk/entities/audiences/bulk_similar_remarketing_list.py deleted file mode 100644 index 340722a1..00000000 --- a/bingads/v12/bulk/entities/audiences/bulk_similar_remarketing_list.py +++ /dev/null @@ -1,123 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkSimilarRemarketingList(_SingleRecordBulkEntity): - """ Represents an Similar Remarketing List that can be read or written in a bulk file. - - This class exposes the :attr:`similar_remarketing_list` property that can be read and written as fields of the - Similar Remarketing List record in a bulk file. - - For more information, see Similar Remarketing List at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - similar_remarketing_list=None, - status=None,): - super(BulkSimilarRemarketingList, self).__init__() - - self._similar_remarketing_list = similar_remarketing_list - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.Id), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.ParentId), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'ParentId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Audience, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.Name), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'Name', v) - ), - _SimpleBulkMapping( - _StringTable.Description, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.Description), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'Description', v) - ), - _SimpleBulkMapping( - _StringTable.MembershipDuration, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.MembershipDuration), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'MembershipDuration', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Scope, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.Scope), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'Scope', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SourceId, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.SourceId), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'SourceId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.AudienceSearchSize, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.SearchSize), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'SearchSize', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AudienceNetworkSize, - field_to_csv=lambda c: bulk_str(c.similar_remarketing_list.AudienceNetworkSize), - csv_to_field=lambda c, v: setattr(c.similar_remarketing_list, 'AudienceNetworkSize', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.SupportedCampaignTypes, - field_to_csv=lambda c: field_to_csv_SupportedCampaignTypes(c.similar_remarketing_list.SupportedCampaignTypes), - csv_to_field=lambda c, v: csv_to_field_SupportedCampaignTypes(c.similar_remarketing_list.SupportedCampaignTypes, v) - ), - ] - - @property - def similar_remarketing_list(self): - """ Defines a Similar Remarketing List """ - - return self._similar_remarketing_list - - @similar_remarketing_list.setter - def similar_remarketing_list(self, similar_remarketing_list): - self._similar_remarketing_list = similar_remarketing_list - - @property - def status(self): - """ The status of the Similar Remarketing List - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.similar_remarketing_list, 'similar_remarketing_list') - self.convert_to_values(row_values, BulkSimilarRemarketingList._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._similar_remarketing_list = _CAMPAIGN_OBJECT_FACTORY_V12.create('SimilarRemarketingList') - row_values.convert_to_entity(self, BulkSimilarRemarketingList._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkSimilarRemarketingList, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bid_suggestion_data.py b/bingads/v12/bulk/entities/bid_suggestion_data.py deleted file mode 100644 index e9a983a8..00000000 --- a/bingads/v12/bulk/entities/bid_suggestion_data.py +++ /dev/null @@ -1,166 +0,0 @@ -from bingads.v12.bulk.entities import PerformanceData - -from bingads.v12.internal.bulk.bulk_object import _BulkObject -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BidSuggestionData: - """ The best position, main line, and first page bid suggestion data corresponding to one keyword. - - If the requested DataScope includes BidSuggestionsData, the download will include bulk records corresponding to the - properties of this class. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - """ - - def __init__(self): - self._best_position = None - self._main_line = None - self._first_page = None - - @property - def best_position(self): - """ Represents a best position bid suggestion that is derived from :class:`_BulkObject`. - - It can only be read from a bulk file by the :class:`.BulkFileReader` when reading the - corresponding :class:`.BulkKeyword`. An instance of this class can represent - a single best position bid, and thus one record in the bulk file. Properties of this class and of classes that - it is derived from, correspond to fields of the Keyword Best Position Bid record in a bulk file. - - For more information, see Keyword Best Position Bid at https://go.microsoft.com/fwlink/?linkid=846127. - - :return: The best position bid suggestion. - :rtype: BulkKeywordBidSuggestion - """ - - return self._best_position - - @best_position.setter - def best_position(self, best_position): - self._best_position = best_position - - @property - def main_line(self): - """ Represents a main line bid suggestion that is derived from :class:`_BulkObject`. - - It can only be read from a bulk file by the :class:`BulkFileReader` when reading the corresponding - :class:`BulkKeyword`. An instance of this class can represent a single main line bid, and thus one record in - the bulk file. Properties of this class and of classes that it is derived from, correspond to fields of the - Keyword Main Line Bid record in a bulk file. - - For more information, see Keyword Main Line Bid at https://go.microsoft.com/fwlink/?linkid=846127. - - :return: The main line bid suggestion. - :rtype: BulkKeywordBidSuggestion - """ - - return self._main_line - - @main_line.setter - def main_line(self, main_line): - self._main_line = main_line - - @property - def first_page(self): - """ Represents a first page bid suggestion that is derived from :class:`_BulkObject`. can only be read from a bulk - file by the :class:`BulkFileReader` when reading the corresponding :class:`BulkKeyword`. An instance of this - class can represent a single first page bid, and thus one record in the bulk file. Properties of this class and - of classes that it is derived from, correspond to fields of the Keyword First Page Bid record in a bulk file. - - For more information, see Keyword First Page Bid at https://go.microsoft.com/fwlink/?linkid=846127. - - :return: The first page bid suggestion. - :rtype: BulkKeywordBidSuggestion - """ - - return self._first_page - - @first_page.setter - def first_page(self, first_page): - self._first_page = first_page - - -class BulkKeywordBidSuggestion(_BulkObject): - """ Represents a best position bid suggestion. - - It can only be read from a bulk file by the :class:`.BulkFileReader` when reading the corresponding :class:`.BulkKeyword`. - An instance of this class can represent a single keyword bid position, and thus one record in the bulk file. - """ - - def __init__(self): - self._keyword_text = None - self._bid = None - self._performance_data = None - - @property - def keyword_text(self): - """ The keyword corresponding to the suggested bid. - - Corresponds to the 'Keyword' field in the bulk file. - :rtype: str - """ - - return self._keyword_text - - @property - def bid(self): - """ The suggested bid for the keyword. - - :rtype: float - """ - - return self._bid - - @property - def performance_data(self): - """ The historical performance data corresponding to the suggested bid. - - :rtype: PerformanceData - """ - - return self._performance_data - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Keyword, - field_to_csv=lambda c: bulk_str(c.keyword_text), - csv_to_field=lambda c, v: setattr(c, '_keyword_text', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Bid, - field_to_csv=lambda c: bulk_str(c.bid), - csv_to_field=lambda c, v: setattr(c, '_bid', float(v) if v else None) - ), - ] - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, BulkKeywordBidSuggestion._MAPPINGS) - self._performance_data = PerformanceData.read_from_row_values(row_values) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, BulkKeywordBidSuggestion._MAPPINGS) - if not exclude_readonly_data: - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) - - @staticmethod - def write_if_not_null(keyword_bid_suggestion, row_writer): - if keyword_bid_suggestion is not None: - row_writer.write_object_row(keyword_bid_suggestion) - - -class BulkKeywordBestPositionBid(BulkKeywordBidSuggestion): - pass - - -class BulkKeywordFirstPageBid(BulkKeywordBidSuggestion): - pass - - -class BulkKeywordMainLineBid(BulkKeywordBidSuggestion): - pass diff --git a/bingads/v12/bulk/entities/bulk_account.py b/bingads/v12/bulk/entities/bulk_account.py deleted file mode 100644 index 23f59317..00000000 --- a/bingads/v12/bulk/entities/bulk_account.py +++ /dev/null @@ -1,137 +0,0 @@ -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.extensions import * - - -class BulkAccount(_SingleRecordBulkEntity): - """ Represents an account that can be read or written in a bulk file. - - Properties of this class and of classes that it is derived from, correspond to fields of the Account record in a bulk file. - For more information, see Account at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, customer_id=None, sync_time=None): - super(BulkAccount, self).__init__() - self._id = account_id - self._customer_id = customer_id - self._sync_time = sync_time - self._msclkid_auto_tagging_enabled = None - self._tracking_url_template = None - self._final_url_suffix = None - - @property - def id(self): - """ The identifier of the account. - - Corresponds to the 'Id' field in the bulk file. - - :return: The identifier of the account. - :rtype: int - """ - - return self._id - - @property - def customer_id(self): - """ The identifier of the customer that contains the account. - - Corresponds to the 'Parent Id' field in the bulk file. - - :return: The identifier of the customer that contains the account. - :rtype: int - """ - - return self._customer_id - - @property - def sync_time(self): - """ The date and time that you last synced your account using the bulk service. - - You should keep track of this value in UTC time. - Corresponds to the 'Sync Time' field in the bulk file. - - :return: The date and time that you last synced your account using the bulk service. - :rtype: datetime.datetime - """ - - return self._sync_time - - @property - def msclkid_auto_tagging_enabled(self): - """ Determines whether auto-tagging of the MSCLKID query string parameter is enabled. The MSCLKID is a 32-character GUID that is unique for each ad click. - :return: The msclkid autotag setting of the account - :rtype: bool - """ - return self._msclkid_auto_tagging_enabled - - @property - def tracking_url_template(self): - """ The tracking template to use as a default for all URLs in your account. - - :return: The tracking template of the account - :rtype: str - """ - return self._tracking_url_template - - @property - def final_url_suffix(self): - """ The final url suffix to use as a default for all URLs in your account. - - :return: The tracking template of the account - :rtype: str - """ - return self._final_url_suffix - - @final_url_suffix.setter - def final_url_suffix(self, v): - self._final_url_suffix = v - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.id), - csv_to_field=lambda c, v: setattr(c, '_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.customer_id), - csv_to_field=lambda c, v: setattr(c, '_customer_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.SyncTime, - field_to_csv=lambda c: bulk_datetime_str(c.sync_time), - csv_to_field=lambda c, v: setattr(c, '_sync_time', parse_datetime(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.MSCLKIDAutoTaggingEnabled, - field_to_csv=lambda c: bulk_str(c.msclkid_auto_tagging_enabled), - csv_to_field=lambda c, v: setattr(c, '_msclkid_auto_tagging_enabled', parse_bool(v)) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.tracking_url_template), - csv_to_field=lambda c, v: setattr(c, '_tracking_url_template', v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.final_url_suffix, c.id), - csv_to_field=lambda c, v: setattr(c, '_final_url_suffix', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - row_values.convert_to_entity(self, BulkAccount._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, BulkAccount._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAccount, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_ad_group.py b/bingads/v12/bulk/entities/bulk_ad_group.py deleted file mode 100644 index fbef5fba..00000000 --- a/bingads/v12/bulk/entities/bulk_ad_group.py +++ /dev/null @@ -1,262 +0,0 @@ -from bingads.v12.bulk.entities import QualityScoreData, PerformanceData -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.extensions import * - -def coop_setting_to_csv(bulk_ad_group, row_values): - if not bulk_ad_group.ad_group.Settings or not bulk_ad_group.ad_group.Settings.Setting: - return - settings = [setting for setting in bulk_ad_group.ad_group.Settings.Setting if isinstance(setting, CoOpSetting_Type)] - if len(settings) == 0: - return - if len(settings) != 1: - raise ValueError('Can only have 1 CoOpSetting in AdGroup Settings.') - - row_values[_StringTable.MaximumBid] = settings[0].BidMaxValue - row_values[_StringTable.BidBoostValue] = settings[0].BidBoostValue - row_values[_StringTable.BidOption] = settings[0].BidOption - pass - -def csv_to_coop_setting(row_values, bulk_ad_group): - maximum_bid_success, maximum_bid = row_values.try_get_value(_StringTable.MaximumBid) - bid_boost_value_success, bid_boost_value = row_values.try_get_value(_StringTable.BidBoostValue) - bid_option_success, bid_option = row_values.try_get_value(_StringTable.BidOption) - - if maximum_bid_success or bid_boost_value_success or bid_option_success: - coop_setting = _CAMPAIGN_OBJECT_FACTORY_V12.create('CoOpSetting') - coop_setting.Type = 'CoOpSetting' - coop_setting.BidOption = bid_option if bid_option else None - coop_setting.BidBoostValue = float(bid_boost_value) if bid_boost_value else None - coop_setting.BidMaxValue = float(maximum_bid) if maximum_bid else None - bulk_ad_group.ad_group.Settings.Setting.append(coop_setting) - pass - -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. - - This class exposes the property :attr:`ad_group` that can be read and written as fields of the Ad Group record - in a bulk file. - - For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, campaign_id=None, campaign_name=None, ad_group=None): - super(BulkAdGroup, self).__init__() - - self._campaign_id = campaign_id - self._campaign_name = campaign_name - self._ad_group = ad_group - - self._quality_score_data = None - self._performance_data = None - - - @property - def campaign_id(self): - """ The identifier of the campaign that contains the ad group. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._campaign_id - - @campaign_id.setter - def campaign_id(self, campaign_id): - self._campaign_id = campaign_id - - @property - def campaign_name(self): - """ The name of the campaign that contains the ad group. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group(self): - """ The AdGroup Data Object of the Campaign Management Service. - - A subset of AdGroup properties are available in the Ad Group record. - For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127. - """ - return self._ad_group - - @ad_group.setter - def ad_group(self, ad_group): - self._ad_group = ad_group - - @property - def quality_score_data(self): - """ The quality score data for the ad group. - - :rtype: QualityScoreData - """ - return self._quality_score_data - - @property - def performance_data(self): - """ The historical performance data for the ad group. - - :rtype: PerformanceData - """ - - return self._performance_data - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.ad_group.Id), - csv_to_field=lambda c, v: setattr(c.ad_group, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: bulk_str(c.ad_group.Status), - csv_to_field=csv_to_status - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.campaign_id), - csv_to_field=lambda c, v: setattr(c, 'campaign_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group.Name, - csv_to_field=lambda c, v: setattr(c.ad_group, 'Name', v) - ), - _SimpleBulkMapping( - header=_StringTable.StartDate, - field_to_csv=lambda c: bulk_date_str(c.ad_group.StartDate), - csv_to_field=lambda c, v: setattr(c.ad_group, 'StartDate', parse_date(v)) - ), - _SimpleBulkMapping( - header=_StringTable.EndDate, - field_to_csv=lambda c: bulk_date_str(c.ad_group.EndDate), - csv_to_field=lambda c, v: setattr(c.ad_group, 'EndDate', parse_date(v)) - ), - _SimpleBulkMapping( - header=_StringTable.NetworkDistribution, - field_to_csv=lambda c: bulk_str(c.ad_group.Network), - csv_to_field=lambda c, v: setattr(c.ad_group, 'Network', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AdRotation, - field_to_csv=lambda c: ad_rotation_bulk_str(c.ad_group.AdRotation, c.ad_group.Id), - csv_to_field=lambda c, v: setattr(c.ad_group, 'AdRotation', parse_ad_rotation(v)) - ), - _SimpleBulkMapping( - header=_StringTable.CpcBid, - field_to_csv=lambda c: ad_group_bid_bulk_str(c.ad_group.CpcBid), - csv_to_field=lambda c, v: setattr(c.ad_group, 'CpcBid', parse_ad_group_bid(v)) - ), - _SimpleBulkMapping( - header=_StringTable.Language, - 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, - field_to_csv=lambda c: bulk_str(c.ad_group.AudienceAdsBidAdjustment), - csv_to_field=lambda c, v: setattr( - c.ad_group, - 'AudienceAdsBidAdjustment', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.ad_group.TrackingUrlTemplate), - csv_to_field=lambda c, v: setattr(c.ad_group, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - 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) - ), - _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme), - - _SimpleBulkMapping( - header=_StringTable.TargetSetting, - field_to_csv=lambda c: target_setting_to_csv(c.ad_group), - csv_to_field=lambda c, v: csv_to_target_setting(c.ad_group, v) - ), - _SimpleBulkMapping( - header=_StringTable.PrivacyStatus, - field_to_csv=lambda c: bulk_str(c.ad_group.PrivacyStatus), - csv_to_field=lambda c, v: setattr(c.ad_group, 'PrivacyStatus', v if v else None) - ), - - _ComplexBulkMapping(coop_setting_to_csv, csv_to_coop_setting), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.ad_group.FinalUrlSuffix, c.ad_group.Id), - csv_to_field=lambda c, v: setattr(c.ad_group, 'FinalUrlSuffix', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.ad_group = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdGroup') - - row_values.convert_to_entity(self, BulkAdGroup._MAPPINGS) - - self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values) - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._ad_group, 'AdGroup') - self.convert_to_values(row_values, BulkAdGroup._MAPPINGS) - if not exclude_readonly_data: - QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values) - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) - - def read_additional_data(self, stream_reader): - super(BulkAdGroup, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_ad_group_dynamic_search_ad_target.py b/bingads/v12/bulk/entities/bulk_ad_group_dynamic_search_ad_target.py deleted file mode 100644 index efa8d80e..00000000 --- a/bingads/v12/bulk/entities/bulk_ad_group_dynamic_search_ad_target.py +++ /dev/null @@ -1,167 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.bulk.entities.common import PerformanceData -from bingads.v12.internal.extensions import * - - -class BulkAdGroupDynamicSearchAdTarget(_SingleRecordBulkEntity): - """ Represents a Ad Group Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Dynamic Search Ad Target record in a bulk file. - - For more information, see Ad Group Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836837. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - campaign_name=None, - ad_group_name=None, - status=None, - biddable_ad_group_criterion=None): - super(BulkAdGroupDynamicSearchAdTarget, self).__init__() - - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._status = status - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._performance_data = None - - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.Bid, - field_to_csv=lambda c: fixed_bid_bulk_str(c.biddable_ad_group_criterion.CriterionBid), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'CriterionBid', parse_fixed_bid(v)) - ), - _SimpleBulkMapping( - header=_StringTable.Name, - field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_WebpageParameter_CriterionName(c.biddable_ad_group_criterion, v) - ), - _ComplexBulkMapping( - entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(c.biddable_ad_group_criterion, v), - csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(v, c.biddable_ad_group_criterion) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_optional_str(c.biddable_ad_group_criterion.TrackingUrlTemplate, c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.biddable_ad_group_criterion, v) - ), - ] - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def status(self): - """ The status of the Ad Group Criterion - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @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 - - @property - def performance_data(self): - return self._performance_data - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage') - self._biddable_ad_group_criterion.Criterion.Type = 'Webpage' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('FixedBid') - self._biddable_ad_group_criterion.CriterionBid.Type = 'FixedBid' - - row_values.convert_to_entity(self, BulkAdGroupDynamicSearchAdTarget._MAPPINGS) - - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupDynamicSearchAdTarget._MAPPINGS) - - PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupDynamicSearchAdTarget, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_ad_group_negative_dynamic_search_ad_target.py b/bingads/v12/bulk/entities/bulk_ad_group_negative_dynamic_search_ad_target.py deleted file mode 100644 index ce5f06f2..00000000 --- a/bingads/v12/bulk/entities/bulk_ad_group_negative_dynamic_search_ad_target.py +++ /dev/null @@ -1,140 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkAdGroupNegativeDynamicSearchAdTarget(_SingleRecordBulkEntity): - """ Represents a Ad Group Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Dynamic Search Ad Target record in a bulk file. - - For more information, see Ad Group Negative Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836838. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - campaign_name=None, - ad_group_name=None, - status=None, - negative_ad_group_criterion=None): - super(BulkAdGroupNegativeDynamicSearchAdTarget, self).__init__() - - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._status = status - self._negative_ad_group_criterion = negative_ad_group_criterion - - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.Name, - field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_WebpageParameter_CriterionName(c.negative_ad_group_criterion, v) - ), - _ComplexBulkMapping( - entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(c.negative_ad_group_criterion, v), - csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(v, c.negative_ad_group_criterion) - ), - ] - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def status(self): - """ The status of the Ad Group Criterion - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def negative_ad_group_criterion(self): - """ Defines a Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage') - self._negative_ad_group_criterion.Criterion.Type = 'Webpage' - - row_values.convert_to_entity(self, BulkAdGroupNegativeDynamicSearchAdTarget._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeDynamicSearchAdTarget._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeDynamicSearchAdTarget, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_ad_group_product_partition.py b/bingads/v12/bulk/entities/bulk_ad_group_product_partition.py deleted file mode 100644 index fb8c182f..00000000 --- a/bingads/v12/bulk/entities/bulk_ad_group_product_partition.py +++ /dev/null @@ -1,292 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.bulk.entities.common import PerformanceData -# from bingads.v12.internal.extensions import bulk_str -from bingads.v12.internal.extensions import * - -_BiddableAdGroupCriterion = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion')) -_NegativeAdGroupCriterion = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion')) -_FixedBid = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('FixedBid')) - -def csv_to_bidding(row_values, entity): - success, exclude = row_values.try_get_value(_StringTable.IsExcluded) - if exclude is None: - exclude = '' - exclude = exclude.lower() - if exclude == 'yes' or exclude == 'true': - is_excluded = True - elif exclude == 'no' or exclude == 'false': - is_excluded = False - else: - raise ValueError('IsExcluded can only be set to TRUE|FALSE in Ad Group Product Partition row') - if is_excluded: - product_partition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductPartition') - product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductCondition') - product_partition.Type = 'ProductPartition' - - negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - negative_ad_group_criterion.Criterion = product_partition - negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - - entity.ad_group_criterion = negative_ad_group_criterion - else: - product_partition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductPartition') - product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductCondition') - product_partition.Type = 'ProductPartition' - - bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('FixedBid') - bid.Type = 'FixedBid' - - biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - biddable_ad_group_criterion.Criterion = product_partition - - success, bid_value = row_values.try_get_value(_StringTable.Bid) - if success and bid_value is not None and bid_value != '': - bid.Amount = float(bid_value) - else: - success, bid_value = row_values.try_get_value(_StringTable.BidAdjustment) - if success and bid_value is not None and bid_value != '': - bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - bid.Type = 'BidMultiplier' - bid.Multiplier = float(bid_value) - - biddable_ad_group_criterion.CriterionBid = bid - biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - - entity.ad_group_criterion = biddable_ad_group_criterion - -def bidding_to_csv(entity, row_values): - if isinstance(entity.ad_group_criterion, _NegativeAdGroupCriterion): - row_values[_StringTable.IsExcluded] = 'True' - else: - row_values[_StringTable.IsExcluded] = 'False' - bid = entity.ad_group_criterion.CriterionBid - if bid is None: - return - if isinstance(bid, _FixedBid): - row_values[_StringTable.Bid] = fixed_bid_bulk_str(bid) - else: - row_values[_StringTable.BidAdjustment] = bid_multiplier_bulk_str(bid) - -class BulkAdGroupProductPartition(_SingleRecordBulkEntity): - """ Represents an Ad Group Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`ad_group_criterion` property that can be read and written as fields of the - Ad Group Product Partition record in a bulk file. - - For more information, see Ad Group Product Scope at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_criterion=None, - campaign_name=None, - ad_group_name=None): - super(BulkAdGroupProductPartition, self).__init__() - - self._ad_group_criterion = ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._performance_data = None - - - @classmethod - def _write_destination_url(cls, entity): - if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion): - return entity.ad_group_criterion.DestinationUrl - else: - return None - - @classmethod - def _get_partition_type(cls, entity): - if entity.ad_group_criterion.Criterion is not None and \ - hasattr(entity.ad_group_criterion.Criterion, 'PartitionType'): - return entity.ad_group_criterion.Criterion.PartitionType - return None - - @classmethod - def _get_parent_criterion_id(cls, entity): - if entity.ad_group_criterion.Criterion is not None and \ - hasattr(entity.ad_group_criterion.Criterion, 'ParentCriterionId'): - return bulk_str(entity.ad_group_criterion.Criterion.ParentCriterionId) - return None - - @classmethod - def _get_condition_operand(cls, entity): - if entity.ad_group_criterion.Criterion is not None and \ - hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \ - entity.ad_group_criterion.Criterion.Condition is not None and \ - hasattr(entity.ad_group_criterion.Criterion.Condition, 'Operand'): - return entity.ad_group_criterion.Criterion.Condition.Operand - return None - - @classmethod - def _get_condition_attribute(cls, entity): - if entity.ad_group_criterion.Criterion is not None and \ - hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \ - entity.ad_group_criterion.Criterion.Condition is not None and \ - hasattr(entity.ad_group_criterion.Criterion.Condition, 'Attribute'): - return entity.ad_group_criterion.Criterion.Condition.Attribute - return None - - @classmethod - def _read_destination_url(cls, entity, row_value): - if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion): - entity.ad_group_criterion.DestinationUrl = row_value - else: - pass - - _MAPPINGS = [ - - _ComplexBulkMapping(bidding_to_csv, csv_to_bidding), - - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: c.ad_group_criterion.Status, - csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Status', v) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.SubType, - field_to_csv=lambda c: BulkAdGroupProductPartition._get_partition_type(c), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion, 'PartitionType', v) - ), - _SimpleBulkMapping( - _StringTable.ParentAdGroupCriterionId, - field_to_csv=lambda c: BulkAdGroupProductPartition._get_parent_criterion_id(c), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion, 'ParentCriterionId', - int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ProductCondition1, - field_to_csv=lambda c: BulkAdGroupProductPartition._get_condition_operand(c), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion.Condition, 'Operand', v) - ), - _SimpleBulkMapping( - _StringTable.ProductValue1, - field_to_csv=lambda c: BulkAdGroupProductPartition._get_condition_attribute(c), - csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion.Condition, 'Attribute', v) - ), - - _SimpleBulkMapping( - _StringTable.DestinationUrl, - field_to_csv=lambda c: BulkAdGroupProductPartition._write_destination_url(c), - csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_destination_url(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.ad_group_criterion.FinalUrls, c.ad_group_criterion.Id) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None, - csv_to_field=lambda c, v: csv_to_field_Urls(c.ad_group_criterion.FinalUrls, v) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None - ), - _SimpleBulkMapping( - header=_StringTable.FinalMobileUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.ad_group_criterion.FinalMobileUrls, c.ad_group_criterion.Id) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None, - csv_to_field=lambda c, v: csv_to_field_Urls(c.ad_group_criterion.FinalMobileUrls, v) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_optional_str(c.ad_group_criterion.TrackingUrlTemplate, c.ad_group_criterion.Id) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None, - csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'TrackingUrlTemplate', v if v else None) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad_group_criterion) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None, - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad_group_criterion, v) - if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.ad_group_criterion.FinalUrlSuffix, c.ad_group_criterion.Id) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None , - csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'FinalUrlSuffix', v) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None - ) - ] - - @property - def ad_group_criterion(self): - """ Defines an Ad Group Criterion """ - - return self._ad_group_criterion - - @ad_group_criterion.setter - def ad_group_criterion(self, ad_group_criterion): - self._ad_group_criterion = ad_group_criterion - - @property - def campaign_name(self): - """ Defines the name of the Campaign. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ Defines the name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def performance_data(self): - return self._performance_data - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.ad_group_criterion, 'ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupProductPartition._MAPPINGS) - - if not exclude_readonly_data: - PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values) - - def process_mappings_from_row_values(self, row_values): - row_values.convert_to_entity(self, BulkAdGroupProductPartition._MAPPINGS) - - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupProductPartition, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_ads.py b/bingads/v12/bulk/entities/bulk_ads.py deleted file mode 100644 index c6f76454..00000000 --- a/bingads/v12/bulk/entities/bulk_ads.py +++ /dev/null @@ -1,775 +0,0 @@ -from bingads.v12.bulk.entities import PerformanceData -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.extensions import * - -# Define type used -ProductAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ProductAd')) -TextAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('TextAd')) -AppInstallAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('AppInstallAd')) -ExpandedTextAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ExpandedTextAd')) -DynamicSearchAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('DynamicSearchAd')) -ResponsiveSearchAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveSearchAd')) -ResponsiveAd = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveAd')) - - -class _BulkAd(_SingleRecordBulkEntity): - """ This abstract base class provides properties that are shared by all bulk ad classes. - - *See also:* - - * :class:`.BulkProductAd` - * :class:`.BulkTextAd` - * :class:`.BulkAppInstallAd` - * :class:`.BulkExpandedTextAd` - * :class:`.BulkDynamicSearchAd` - * :class:`.BulkResponsiveAd` - * :class:`.BulkResponsiveSearchAd` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(_BulkAd, self).__init__() - - self._ad_group_id = ad_group_id - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._ad = ad - self._performance_data = None - - @property - def ad_group_id(self): - """ The identifier of the ad group that contains the ad. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._ad_group_id - - @ad_group_id.setter - def ad_group_id(self, ad_group_id): - self._ad_group_id = ad_group_id - - @property - def campaign_name(self): - """ The name of the campaign that contains the ad. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the ad group that contains the ad. - - Corresponds to the 'Ad Group' field in the bulk file. - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def ad(self): - """ The type of ad. - - """ - - return self._ad - - @ad.setter - def ad(self, ad): - self._ad = ad - - @property - def performance_data(self): - """ The historical performance data for the ad. - - :rtype: PerformanceData - """ - - return self._performance_data - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: bulk_str(c.ad.Status), - csv_to_field=lambda c, v: setattr(c.ad, 'Status', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.ad.Id), - csv_to_field=lambda c, v: setattr(c.ad, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.ad_group_id), - csv_to_field=lambda c, v: setattr(c, '_ad_group_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, '_campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialStatus, - field_to_csv=lambda c: c.ad.EditorialStatus, - csv_to_field=lambda c, v: setattr(c.ad, 'EditorialStatus', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.DevicePreference, - field_to_csv=lambda c: bulk_device_preference_str(c.ad.DevicePreference), - csv_to_field=lambda c, v: setattr(c.ad, 'DevicePreference', parse_device_preference(v)) - ), - - _SimpleBulkMapping( - header=_StringTable.AdFormatPreference, - field_to_csv=lambda c: bulk_str(c.ad.AdFormatPreference), - csv_to_field=lambda c, v: setattr(c.ad, 'AdFormatPreference', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalUrls, c.ad.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.ad.FinalUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalMobileUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalMobileUrls, c.ad.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.ad.FinalMobileUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.ad.TrackingUrlTemplate), - csv_to_field=lambda c, v: setattr(c.ad, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.ad.FinalUrlSuffix, c.ad.Id), - csv_to_field=lambda c, v: setattr(c.ad, 'FinalUrlSuffix', v) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, _BulkAd._MAPPINGS) - if not exclude_readonly_data: - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) - - def process_mappings_from_row_values(self, row_values): - row_values.convert_to_entity(self, _BulkAd._MAPPINGS) - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def read_additional_data(self, stream_reader): - super(_BulkAd, self).read_additional_data(stream_reader) - - -class BulkProductAd(_BulkAd): - """ Represents a product ad. - - This class exposes the :attr:`product_ad` property that can be read and written as fields of the Product Ad record in a bulk file. - - For more information, see Product Ad at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkProductAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad - ) - self.product_ad = ad - - @property - def product_ad(self): - """ The product ad. - - See Product Ad at: https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad - - @product_ad.setter - def product_ad(self, product_ad): - if product_ad is not None and not isinstance(product_ad, ProductAd): - raise ValueError('Not an instance of ProductAd') - self._ad = product_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.PromotionalText, - field_to_csv=lambda c: bulk_optional_str(c.product_ad.PromotionalText, c.product_ad.Id), - csv_to_field=lambda c, v: setattr(c.product_ad, 'PromotionalText', v if v else '') - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.product_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductAd') - self.product_ad.Type = 'Product' - super(BulkProductAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkProductAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.product_ad, 'product_ad') - super(BulkProductAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkProductAd._MAPPINGS) - - -class BulkTextAd(_BulkAd): - """ Represents a Text Ad. - - This class exposes the :attr:`text_ad` property that can be read and written as fields of the Text Ad record in a bulk file. - - For more information, see Text Ad at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkTextAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self.text_ad = ad - - @property - def text_ad(self): - """ The text ad. - - see Text Ad at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad - - @text_ad.setter - def text_ad(self, text_ad): - if text_ad is not None and not isinstance(text_ad, TextAd): - raise ValueError('Not an instance of TextAd') - self._ad = text_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Title, - field_to_csv=lambda c: c.text_ad.Title, - csv_to_field=lambda c, v: setattr(c.text_ad, 'Title', v) - ), - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.text_ad.Text, - csv_to_field=lambda c, v: setattr(c.text_ad, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.DisplayUrl, - field_to_csv=lambda c: bulk_optional_str(c.text_ad.DisplayUrl, c.text_ad.Id), - csv_to_field=lambda c, v: setattr(c.text_ad, 'DisplayUrl', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.DestinationUrl, - field_to_csv=lambda c: bulk_optional_str(c.text_ad.DestinationUrl, c.text_ad.Id), - csv_to_field=lambda c, v: setattr(c.text_ad, 'DestinationUrl', v if v else '') - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.text_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('TextAd') - self.text_ad.Type = 'Text' - super(BulkTextAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkTextAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.text_ad, 'text_ad') - super(BulkTextAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkTextAd._MAPPINGS) - - -class BulkAppInstallAd(_BulkAd): - """ Represents an App Install Ad. - - This class exposes the :attr:`app_install_ad` property that can be read and written as fields of the App Install Ad record in a bulk file. - - For more information, see App Install Ad at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkAppInstallAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self.app_install_ad = ad - - @property - def app_install_ad(self): - """ The App Install Ad. - - see App Install Ad at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad - - @app_install_ad.setter - def app_install_ad(self, app_install_ad): - if app_install_ad is not None and not isinstance(app_install_ad, AppInstallAd): - raise ValueError('Not an instance of AppInstallAd') - self._ad = app_install_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.AppPlatform, - field_to_csv=lambda c: c.app_install_ad.AppPlatform, - csv_to_field=lambda c, v: setattr(c.app_install_ad, 'AppPlatform', v) - ), - _SimpleBulkMapping( - header=_StringTable.AppStoreId, - field_to_csv=lambda c: c.app_install_ad.AppStoreId, - csv_to_field=lambda c, v: setattr(c.app_install_ad, 'AppStoreId', v) - ), - _SimpleBulkMapping( - header=_StringTable.Title, - field_to_csv=lambda c: c.app_install_ad.Title, - csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Title', v) - ), - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.app_install_ad.Text, - csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Text', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.app_install_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('AppInstallAd') - self.app_install_ad.Type = 'AppInstall' - super(BulkAppInstallAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkAppInstallAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.app_install_ad, 'app_install_ad') - super(BulkAppInstallAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkAppInstallAd._MAPPINGS) - - -class BulkExpandedTextAd(_BulkAd): - """ Represents an Expanded Text Ad. - - This class exposes the :attr:`expanded_text_ad` property that can be read and written as fields of the Expanded Text Ad record in a bulk file. - - For more information, see Expanded Text Ad at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkExpandedTextAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self.expanded_text_ad = ad - - @property - def expanded_text_ad(self): - """ The Expanded Text Ad. - - see Expanded Text Ad at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad - - @expanded_text_ad.setter - def expanded_text_ad(self, expanded_text_ad): - if expanded_text_ad is not None and not isinstance(expanded_text_ad, ExpandedTextAd): - raise ValueError('Not an instance of ExpandedTextAd') - self._ad = expanded_text_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.expanded_text_ad.Text, - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.TextPart2, - field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.TextPart2, c.expanded_text_ad.Id), - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TextPart2', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.TitlePart1, - field_to_csv=lambda c: c.expanded_text_ad.TitlePart1, - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart1', v) - ), - _SimpleBulkMapping( - header=_StringTable.TitlePart2, - field_to_csv=lambda c: c.expanded_text_ad.TitlePart2, - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart2', v) - ), - _SimpleBulkMapping( - header=_StringTable.TitlePart3, - field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.TitlePart3, c.expanded_text_ad.Id), - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart3', v if v else '') - ), - _SimpleBulkMapping( - header=_StringTable.Path1, - field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Path1, c.expanded_text_ad.Id), - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Path1', v) - ), - _SimpleBulkMapping( - header=_StringTable.Path2, - field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Path2, c.expanded_text_ad.Id), - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Path2', v) - ), - _SimpleBulkMapping( - header=_StringTable.Domain, - field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Domain, c.expanded_text_ad.Id), - csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Domain', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.expanded_text_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ExpandedTextAd') - self.expanded_text_ad.Type = 'ExpandedText' - super(BulkExpandedTextAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkExpandedTextAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.expanded_text_ad, 'expanded_text_ad') - super(BulkExpandedTextAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkExpandedTextAd._MAPPINGS) - - -class BulkDynamicSearchAd(_BulkAd): - """ Represents a Dynamic Search Ad. - - This class exposes the :attr:`dynamic_search_ad` property that can be read and written as fields of the Dynamic Search Ad record in a bulk file. - - For more information, see Dynamic Search Ad at https://go.microsoft.com/fwlink/?linkid=836840. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkDynamicSearchAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self.dynamic_search_ad = ad - - @property - def dynamic_search_ad(self): - """ The dynamic search ad. - - see Dynamic Search Ad at https://go.microsoft.com/fwlink/?linkid=836840. - """ - - return self._ad - - @dynamic_search_ad.setter - def dynamic_search_ad(self, dynamic_search_ad): - if dynamic_search_ad is not None and not isinstance(dynamic_search_ad, DynamicSearchAd): - raise ValueError('Not an instance of DynamicSearchAd') - self._ad = dynamic_search_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.dynamic_search_ad.Text, - csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.Path1, - field_to_csv=lambda c: c.dynamic_search_ad.Path1, - csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Path1', v) - ), - _SimpleBulkMapping( - header=_StringTable.Path2, - field_to_csv=lambda c: c.dynamic_search_ad.Path2, - csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Path2', v) - ), - _SimpleBulkMapping( - header=_StringTable.TextPart2, - field_to_csv=lambda c: c.dynamic_search_ad.TextPart2, - csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'TextPart2', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.dynamic_search_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('DynamicSearchAd') - self.dynamic_search_ad.Type = 'DynamicSearch' - super(BulkDynamicSearchAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkDynamicSearchAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.dynamic_search_ad, 'dynamic_search_ad') - super(BulkDynamicSearchAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkDynamicSearchAd._MAPPINGS) - - -class BulkResponsiveAd(_BulkAd): - """ Represents a Responsive Ad. - - This class exposes the :attr:`responsive_ad` property that can be read and written as fields of the Responsive Ad record in a bulk file. - - For more information, see Responsive Ad at https://go.microsoft.com/fwlink/?linkid=836840. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkResponsiveAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self._ad = ad - - @property - def responsive_ad(self): - """ The responsive search ad. - - see Responsive Ad at https://go.microsoft.com/fwlink/?linkid=836840. - """ - - return self._ad - - @responsive_ad.setter - def responsive_ad(self, responsive_ad): - if responsive_ad is not None and not isinstance(responsive_ad, ResponsiveAd): - raise ValueError('Not an instance of ResponsiveAd') - self._ad = responsive_ad - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.BusinessName, - field_to_csv=lambda c: c.responsive_ad.BusinessName, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'BusinessName', v) - ), - _SimpleBulkMapping( - header=_StringTable.CallToAction, - field_to_csv=lambda c: c.responsive_ad.CallToAction, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'CallToAction', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Headline, - field_to_csv=lambda c: c.responsive_ad.Headline, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'Headline', v) - ), - _SimpleBulkMapping( - header=_StringTable.LongHeadline, - field_to_csv=lambda c: c.responsive_ad.LongHeadline, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LongHeadline', v) - ), - _SimpleBulkMapping( - header=_StringTable.LandscapeImageMediaId, - field_to_csv=lambda c: c.responsive_ad.LandscapeImageMediaId, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LandscapeImageMediaId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.LandscapeLogoMediaId, - field_to_csv=lambda c: c.responsive_ad.LandscapeLogoMediaId, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LandscapeLogoMediaId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.SquareImageMediaId, - field_to_csv=lambda c: c.responsive_ad.SquareImageMediaId, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'SquareImageMediaId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.SquareLogoMediaId, - field_to_csv=lambda c: c.responsive_ad.SquareLogoMediaId, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'SquareLogoMediaId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Text, - field_to_csv=lambda c: c.responsive_ad.Text, - csv_to_field=lambda c, v: setattr(c.responsive_ad, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.Images, - field_to_csv=lambda c: field_to_csv_ImageAssetLinks(c.responsive_ad.Images), - csv_to_field=lambda c, v: csv_to_field_ImageAssetLinks(c.responsive_ad.Images, v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self.responsive_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveAd') - self.responsive_ad.Type = 'Responsive' - super(BulkResponsiveAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkResponsiveAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.responsive_ad, 'responsive_ad') - super(BulkResponsiveAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkResponsiveAd._MAPPINGS) - -class BulkResponsiveSearchAd(_BulkAd): - """ Represents a Responsive Search Ad. - - This class exposes the :attr:`responsive_search_ad` property that can be read and written as fields of the Responsive Search Ad record in a bulk file. - - For more information, see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_id=None, - campaign_name=None, - ad_group_name=None, - ad=None): - super(BulkResponsiveSearchAd, self).__init__( - ad_group_id, - campaign_name, - ad_group_name, - ad, - ) - self._ad = ad - - @property - def responsive_search_ad(self): - """ The responsive search ad. - - see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840. - """ - - return self._ad - - @responsive_search_ad.setter - def responsive_search_ad(self, rsa): - if rsa is not None and not isinstance(rsa, ResponsiveSearchAd): - raise ValueError('Not an instance of ResponsiveSearchAd') - self._ad = rsa - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Path1, - field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Path1, c.responsive_search_ad.Id), - csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path1', v) - ), - _SimpleBulkMapping( - header=_StringTable.Path2, - field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Path2, c.responsive_search_ad.Id), - csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path2', v) - ), - _SimpleBulkMapping( - header=_StringTable.Domain, - field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Domain, c.responsive_search_ad.Id), - csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Domain', v) - ), - _SimpleBulkMapping( - header=_StringTable.Headline, - field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(c.responsive_search_ad.Headlines), - csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(c.responsive_search_ad.Headlines, v) - ), - _SimpleBulkMapping( - header=_StringTable.Description, - field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(c.responsive_search_ad.Descriptions), - csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(c.responsive_search_ad.Descriptions ,v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.responsive_search_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveSearchAd') - self.responsive_search_ad.Type = 'ResponsiveSearch' - super(BulkResponsiveSearchAd, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkResponsiveSearchAd._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.responsive_search_ad, 'responsive_search_ad') - super(BulkResponsiveSearchAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkResponsiveSearchAd._MAPPINGS) \ No newline at end of file diff --git a/bingads/v12/bulk/entities/bulk_budget.py b/bingads/v12/bulk/entities/bulk_budget.py deleted file mode 100644 index 62637c4f..00000000 --- a/bingads/v12/bulk/entities/bulk_budget.py +++ /dev/null @@ -1,109 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.extensions import * -from decimal import Decimal - - -class BulkBudget(_SingleRecordBulkEntity): - """ Represents a budget that can be read or written in a bulk file. - - Properties of this class and of classes that it is derived from, correspond to fields of the Budget record in a bulk file. - For more information, see Budget at https://go.microsoft.com/fwlink/?linkid=846127 - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, budget=None, status=None, account_id=None): - super(BulkBudget, self).__init__() - self._budget = budget - self._status = status - self._account_id = account_id - - @property - def budget(self): - """ - the Budget object, see more detail at: https://go.microsoft.com/fwlink/?linkid=846127 - """ - return self._budget - - @budget.setter - def budget(self, value): - self._budget = 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 - - @property - def account_id(self): - """ the id of the account which contains the budget - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: long - """ - return self._account_id - - @account_id.setter - def account_id(self, value): - self._account_id = value - - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.budget.Id), - csv_to_field=lambda c, v: setattr(c.budget, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.account_id), - csv_to_field=lambda c, v: setattr(c, 'account_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - header=_StringTable.BudgetName, - field_to_csv=lambda c: bulk_str(c.budget.Name), - csv_to_field=lambda c, v: setattr(c.budget, 'Name', v) - ), - _SimpleBulkMapping( - header=_StringTable.BudgetType, - field_to_csv=lambda c: bulk_str(c.budget.BudgetType), - csv_to_field=lambda c, v: csv_to_field_BudgetType(c.budget, v) - ), - _SimpleBulkMapping( - header=_StringTable.Budget, - field_to_csv=lambda c: bulk_str(c.budget.Amount), - csv_to_field=lambda c, v: setattr(c.budget, 'Amount', Decimal(v) if v else None) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self._budget = _CAMPAIGN_OBJECT_FACTORY_V12.create('Budget') - row_values.convert_to_entity(self, BulkBudget._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.budget, 'budget') - self.convert_to_values(row_values, BulkBudget._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkBudget, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_campaign.py b/bingads/v12/bulk/entities/bulk_campaign.py deleted file mode 100644 index 8b06c471..00000000 --- a/bingads/v12/bulk/entities/bulk_campaign.py +++ /dev/null @@ -1,447 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.bulk.entities import QualityScoreData, PerformanceData -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.extensions import * - -_ShoppingSetting = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ShoppingSetting')) -_DsaSetting = type(_CAMPAIGN_OBJECT_FACTORY_V12.create('DynamicSearchAdsSetting')) - -class BulkCampaign(_SingleRecordBulkEntity): - """ Represents a campaign that can be read or written in a bulk file. - - This class exposes the :attr:`campaign` property that can be read and written as fields of the - Campaign record in a bulk file. - - For more information, see Campaign at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, account_id=None, campaign=None): - super(BulkCampaign, self).__init__() - - self._account_id = account_id - self._campaign = campaign - self._quality_score_data = None - self._performance_data = None - self._budget_name = None - - @property - def account_id(self): - """ The identifier of the account that contains the campaign. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._account_id - - @account_id.setter - def account_id(self, account_id): - self._account_id = account_id - - @property - def budget_name(self): - """ - The budget name that the campaign associated, only for campaigns that use a shared budget - - Corresponds to 'Budget Name' field in bulk file. - :rtype: str - """ - return self._budget_name - - @budget_name.setter - def budget_name(self, value): - self._budget_name = value - - @property - def campaign(self): - """ Defines a campaign within an account. - - See Campaign at https://docs.microsoft.com/en-us/bingads/campaign-management-service/campaign?view=bingads-12 - """ - - return self._campaign - - @campaign.setter - def campaign(self, campaign): - self._campaign = campaign - - @property - def quality_score_data(self): - """ The quality score data for the campaign. - - :rtype: QualityScoreData - """ - - return self._quality_score_data - - @property - def performance_data(self): - """ The historical performance data for the campaign - - :rtype: PerformanceData - """ - - return self._performance_data - - def _get_shopping_setting(self): - return self._get_setting(_ShoppingSetting, 'ShoppingSetting') - - def _get_target_setting(self): - return self._get_setting(_ShoppingSetting, 'TargetSetting') - - def _get_dsa_setting(self): - return self._get_setting(_DsaSetting, 'DynamicSearchAdsSetting') - - def _get_setting(self, setting_type, setting_name): - if not self.campaign.Settings.Setting: - return None - settings = [setting for setting in self.campaign.Settings.Setting if - isinstance(setting, setting_type)] - if len(settings) != 1: - raise ValueError('Can only have 1 ' + setting_name + ' in Campaign Settings.') - return settings[0] - - @staticmethod - def _write_campaign_type(c): - if not c.campaign.CampaignType: - return None - if len(c.campaign.CampaignType) != 1: - raise ValueError("Only 1 CampaignType can be set in Campaign") - return c.campaign.CampaignType[0] - - @staticmethod - def _read_campaign_type(c, v): - if not v: - return [] - campaign_type = v - c.campaign.CampaignType = [campaign_type] - - if campaign_type.lower() == 'shopping' or campaign_type.lower() == 'audience': - BulkCampaign._create_campaign_setting(c.campaign, 'ShoppingSetting') - elif campaign_type.lower() == 'dynamicsearchads': - BulkCampaign._create_campaign_setting(c.campaign, 'DynamicSearchAdsSetting') - - @staticmethod - def _create_campaign_setting(campaign, setting_type): - campaign.Settings = _CAMPAIGN_OBJECT_FACTORY_V12.create('ArrayOfSetting') - setting = _CAMPAIGN_OBJECT_FACTORY_V12.create(setting_type) - setting.Type = setting_type - campaign.Settings.Setting = [setting] - - @staticmethod - def _write_store_id(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - return bulk_str(shopping_setting.StoreId) - - @staticmethod - def _read_store_id(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - shopping_setting.StoreId = int(v) if v else None - - @staticmethod - def _write_priority(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - return bulk_str(shopping_setting.Priority) - - @staticmethod - def _read_priority(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - shopping_setting.Priority = int(v) if v else None - - @staticmethod - def _write_sales_country_code(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - return shopping_setting.SalesCountryCode - - @staticmethod - def _read_sales_country_code(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - shopping_setting.SalesCountryCode = v - - @staticmethod - def _write_local_inventory_ads_enabled(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - return shopping_setting.LocalInventoryAdsEnabled - - @staticmethod - def _read_local_inventory_ads_enabled(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'shopping' in campgaign_types or 'audience' in campgaign_types: - shopping_setting = c._get_shopping_setting() - if not shopping_setting: - return None - shopping_setting.LocalInventoryAdsEnabled = v.lower() == 'true' if v else None - - @staticmethod - def _read_source(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - dsa_setting.Source = v - - @staticmethod - def _write_source(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - return bulk_str(dsa_setting.Source) - - @staticmethod - def _read_domain_language(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - dsa_setting.Language = v - - @staticmethod - def _write_domain_language(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - return bulk_str(dsa_setting.Language) - - @staticmethod - def _read_website(c, v): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - dsa_setting.DomainName = v - - @staticmethod - def _write_website(c): - if not c.campaign.CampaignType: - return None - campgaign_types = [campaign_type.lower() for campaign_type in c.campaign.CampaignType] - if 'dynamicsearchads' in campgaign_types: - dsa_setting = c._get_dsa_setting() - if not dsa_setting: - return None - return bulk_str(dsa_setting.DomainName) - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.CampaignType, - field_to_csv=lambda c: BulkCampaign._write_campaign_type(c), - csv_to_field=lambda c, v: BulkCampaign._read_campaign_type(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: bulk_str(c.campaign.Status), - csv_to_field=lambda c, v: setattr( - c.campaign, - 'Status', - v if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.campaign.Id), - csv_to_field=lambda c, v: setattr( - c.campaign, - 'Id', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.account_id), - csv_to_field=lambda c, v: setattr(c, '_account_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign.Name, - csv_to_field=lambda c, v: setattr(c.campaign, 'Name', v) - ), - _SimpleBulkMapping( - header=_StringTable.TimeZone, - 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, - field_to_csv=lambda c: bulk_str(c.campaign.AudienceAdsBidAdjustment), - csv_to_field=lambda c, v: setattr( - c.campaign, - 'AudienceAdsBidAdjustment', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.BingMerchantCenterId, - field_to_csv=lambda c: BulkCampaign._write_store_id(c), - csv_to_field=lambda c, v: BulkCampaign._read_store_id(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.CampaignPriority, - field_to_csv=lambda c: BulkCampaign._write_priority(c), - csv_to_field=lambda c, v: BulkCampaign._read_priority(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.CountryCode, - field_to_csv=lambda c: BulkCampaign._write_sales_country_code(c), - csv_to_field=lambda c, v: BulkCampaign._read_sales_country_code(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.LocalInventoryAdsEnabled, - field_to_csv=lambda c: BulkCampaign._write_local_inventory_ads_enabled(c), - csv_to_field=lambda c, v: BulkCampaign._read_local_inventory_ads_enabled(c, v) - ), - _SimpleBulkMapping( - 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) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.campaign), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.campaign, v) - ), - _ComplexBulkMapping(biddingscheme_to_csv, csv_to_biddingscheme), - _SimpleBulkMapping( - header=_StringTable.BudgetId, - field_to_csv=lambda c: bulk_str(c.campaign.BudgetId), - csv_to_field=lambda c, v: setattr(c.campaign, 'BudgetId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.BudgetType, - field_to_csv=lambda c: bulk_str(c.campaign.BudgetType), - csv_to_field=lambda c, v: csv_to_field_BudgetType(c.campaign, v, version=12) - ), - _SimpleBulkMapping( - header=_StringTable.BudgetName, - field_to_csv=lambda c: bulk_str(c.budget_name), - csv_to_field=lambda c, v: setattr(c, 'budget_name', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Website, - field_to_csv=lambda c: BulkCampaign._write_website(c), - csv_to_field=lambda c, v: BulkCampaign._read_website(c, v) - - ), - _SimpleBulkMapping( - header=_StringTable.DomainLanguage, - field_to_csv=lambda c: BulkCampaign._write_domain_language(c), - csv_to_field=lambda c, v: BulkCampaign._read_domain_language(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.Source, - field_to_csv=lambda c: BulkCampaign._write_source(c), - csv_to_field=lambda c, v: BulkCampaign._read_source(c, v) - ), - _SimpleBulkMapping( - header=_StringTable.SubType, - field_to_csv=lambda c: c.campaign.SubType, - csv_to_field=lambda c, v: setattr(c.campaign, 'SubType', v) - ), - _SimpleBulkMapping( - header=_StringTable.ExperimentId, - field_to_csv=lambda c: bulk_str(c.campaign.ExperimentId), - csv_to_field=lambda c, v: setattr(c.campaign, 'ExperimentId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.TargetSetting, - field_to_csv=lambda c: target_setting_to_csv(c.campaign), - csv_to_field=lambda c, v: csv_to_target_setting(c.campaign, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.campaign.FinalUrlSuffix, c.campaign.Id), - csv_to_field=lambda c, v: setattr(c.campaign, 'FinalUrlSuffix', v) - ), - ] - - def read_additional_data(self, stream_reader): - super(BulkCampaign, self).read_additional_data(stream_reader) - - def process_mappings_from_row_values(self, row_values): - self._campaign = _CAMPAIGN_OBJECT_FACTORY_V12.create('Campaign') - row_values.convert_to_entity(self, BulkCampaign._MAPPINGS) - self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values) - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.campaign, 'campaign') - self.convert_to_values(row_values, BulkCampaign._MAPPINGS) - if not exclude_readonly_data: - QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values) - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) diff --git a/bingads/v12/bulk/entities/bulk_campaign_negative_dynamic_search_ad_target.py b/bingads/v12/bulk/entities/bulk_campaign_negative_dynamic_search_ad_target.py deleted file mode 100644 index 2776c3cc..00000000 --- a/bingads/v12/bulk/entities/bulk_campaign_negative_dynamic_search_ad_target.py +++ /dev/null @@ -1,116 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - - -class BulkCampaignNegativeDynamicSearchAdTarget(_SingleRecordBulkEntity): - """ Represents a Campaign Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_campaign_criterion` property that can be read and written as fields of the - Campaign Negative Dynamic Search Ad Target record in a bulk file. - - For more information, see Campaign Negative Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836839. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - campaign_name=None, - status=None, - negative_campaign_criterion=None): - super(BulkCampaignNegativeDynamicSearchAdTarget, self).__init__() - - self._campaign_name = campaign_name - self._status = status - self._negative_campaign_criterion = negative_campaign_criterion - - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.status, - csv_to_field=lambda c, v: setattr(c, 'status', v) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.Name, - field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(c.negative_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_WebpageParameter_CriterionName(c.negative_campaign_criterion, v) - ), - _ComplexBulkMapping( - entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(c.negative_campaign_criterion, v), - csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(v, c.negative_campaign_criterion) - ) - ] - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def status(self): - """ The status of the Campaign Criterion - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def negative_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._negative_campaign_criterion - - @negative_campaign_criterion.setter - def negative_campaign_criterion(self, negative_campaign_criterion): - self._negative_campaign_criterion = negative_campaign_criterion - - def process_mappings_from_row_values(self, row_values): - self._negative_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeCampaignCriterion') - self._negative_campaign_criterion.Type = 'NegativeCampaignCriterion' - self._negative_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage') - self._negative_campaign_criterion.Criterion.Type = 'Webpage' - - row_values.convert_to_entity(self, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_campaign_criterion, 'negative_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignNegativeDynamicSearchAdTarget, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_campaign_product_scope.py b/bingads/v12/bulk/entities/bulk_campaign_product_scope.py deleted file mode 100644 index 68e85544..00000000 --- a/bingads/v12/bulk/entities/bulk_campaign_product_scope.py +++ /dev/null @@ -1,122 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.bulk.entities.common import _ProductConditionHelper -from bingads.v12.internal.extensions import bulk_str - - -class BulkCampaignProductScope(_SingleRecordBulkEntity): - """ Represents a Campaign Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`campaign_criterion` property that can be read and written as fields of the - Campaign Product Scope record in a bulk file. - - For more information, see Campaign Product Scope at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - campaign_name=None, - status=None, - biddable_campaign_criterion=None): - super(BulkCampaignProductScope, self).__init__() - - self._campaign_name = campaign_name - self._status = status - self._biddable_campaign_criterion = biddable_campaign_criterion - - @classmethod - def _add_product_condition_to_row_values(cls, entity, value): - criterion = entity.biddable_campaign_criterion.Criterion - if criterion is not None and hasattr(criterion, 'Conditions') and criterion.Conditions is not None and \ - hasattr(criterion.Conditions, 'ProductCondition'): - return _ProductConditionHelper.add_row_values_from_conditions(criterion.Conditions.ProductCondition, value) - return None - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: c.biddable_campaign_criterion.Status, - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _ComplexBulkMapping( - entity_to_csv=lambda c, v: BulkCampaignProductScope._add_product_condition_to_row_values(c, v), - csv_to_entity=lambda v, c: _ProductConditionHelper.add_conditions_from_row_values( - v, - c.biddable_campaign_criterion.Criterion.Conditions.ProductCondition - ) - ) - ] - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def status(self): - """ The status of the Campaign Criterion - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def biddable_campaign_criterion(self): - """ Defines a Biddable Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductScope') - self._biddable_campaign_criterion.Criterion.Type = 'ProductScope' - - row_values.convert_to_entity(self, BulkCampaignProductScope._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignProductScope._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignProductScope, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/bulk_entity.py b/bingads/v12/bulk/entities/bulk_entity.py deleted file mode 100644 index e0a8f4fd..00000000 --- a/bingads/v12/bulk/entities/bulk_entity.py +++ /dev/null @@ -1,47 +0,0 @@ -from abc import ABCMeta, abstractproperty - -from future.utils import with_metaclass - -from bingads.internal.error_messages import _ErrorMessages -from bingads.v12.internal.bulk.bulk_object import _BulkObject - - -class BulkEntity(with_metaclass(ABCMeta, _BulkObject)): - """ The abstract base class for all bulk entities that can be read or written in a bulk file. - - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - @abstractproperty - def has_errors(self): - """ Determines whether the bulk entity has associated errors. - - :rtype: bool - """ - - raise NotImplementedError() - - @abstractproperty - def last_modified_time(self): - """ Gets the last modified time for the entity. - - :rtype: :class:`datetime.datetime` - """ - - raise NotImplementedError() - - def _validate_property_not_null(self, property_value, property_name): - if property_value is None: - raise ValueError(_ErrorMessages.get_property_must_not_be_null_message(type(self).__name__, property_name)) - - def _validate_list_not_null_or_empty(self, list_object, list_value, property_name): - self._validate_property_not_null(list_object, property_name) - if not list_value: - raise ValueError(_ErrorMessages.get_list_must_not_be_null_or_empty(type(self).__name__, property_name)) diff --git a/bingads/v12/bulk/entities/bulk_error.py b/bingads/v12/bulk/entities/bulk_error.py deleted file mode 100644 index a038db7d..00000000 --- a/bingads/v12/bulk/entities/bulk_error.py +++ /dev/null @@ -1,178 +0,0 @@ -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.bulk_object import _BulkObject -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.extensions import * - - -class BulkError(_BulkObject): - """ Contains bulk file error details in a separate record that corresponds to the record of a :class:`.BulkEntity` derived instance. - - Properties of this class and of classes that it is derived from, correspond to error fields of the 'Error' records in a bulk file. - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - - *Example:* - - If you upload a :class:`.BulkCampaign` without setting the campaign name using :meth:`BulkServiceManager.upload_entities, - and if you request errors to be returned in the results using the corresponding :attr:`SubmitUploadParameters.response_mode`, - then the upload result file will contain a record that can be read with a :class:`.BulkFileReader` as an instance of :class:`.BulkError`. - """ - - def __init__(self): - self._error = None - self._number = None - self._editorial_location = None - self._editorial_term = None - self._editorial_reason_code = None - self._publisher_countries = None - self._entity = None - self._field_path = None - - @property - def entity(self): - return self._entity - - @entity.setter - def entity(self, value): - self._entity = value - - @property - def error(self): - """ The error code, for example 'CampaignServiceEditorialValidationError'. - - Corresponds to the 'Error' field in the bulk file. - For more information, see Bing Ads Operation Error Codes at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: str - """ - - return self._error - - @property - def number(self): - """ The error number, for example '1042'. - - Corresponds to the 'Error Number' field in the bulk file. - For more information, see Bing Ads Operation Error Codes at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: int - """ - - return self._number - - @property - def editorial_location(self): - """ The location of the entity property that resulted in the editorial error, for example 'AdDescription'. - - Corresponds to the 'Editorial Location' field in the bulk file. - - :rtype: str - """ - - return self._editorial_location - - @property - def editorial_term(self): - """ The term that resulted in the editorial error, for example 'bing'. - - Corresponds to the 'Editorial Term' field in the bulk file. - - :rtype: str - """ - - return self._editorial_term - - @property - def editorial_reason_code(self): - """ The term that resulted in the editorial error, for example '17'. - - Corresponds to the 'Editorial Reason Code' field in the bulk file. - For more information, see Bing Ads Editorial Failure Reason Codes at https://go.microsoft.com/fwlink/?linkid=846127. - - :rtype: int - """ - - return self._editorial_reason_code - - - @property - def field_path(self): - """ The term that resulted in the editorial error. - - Corresponds to the 'Field Path' field in the bulk file. - - :rtype: int - """ - - return self._field_path - - @property - def publisher_countries(self): - """ The publisher countries where editorial restriction is enforced, for example 'US'. - - Corresponds to the 'Publisher Countries' field in the bulk file. - - *Remarks:* - - In a bulk file, the list of publisher countries are delimited with a semicolon (;). - - :rtype: str - """ - - return self._publisher_countries - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Error, - field_to_csv=lambda c: bulk_str(c.error), - csv_to_field=lambda c, v: setattr(c, '_error', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ErrorNumber, - field_to_csv=lambda c: bulk_str(c.number), - csv_to_field=lambda c, v: setattr(c, '_number', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialLocation, - field_to_csv=lambda c: bulk_str(c.editorial_location), - csv_to_field=lambda c, v: setattr(c, '_editorial_location', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialReasonCode, - field_to_csv=lambda c: bulk_str(c.editorial_reason_code), - csv_to_field=lambda c, v: setattr(c, '_editorial_reason_code', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialTerm, - field_to_csv=lambda c: bulk_str(c.editorial_term), - csv_to_field=lambda c, v: setattr(c, '_editorial_term', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.PublisherCountries, - field_to_csv=lambda c: bulk_str(c.publisher_countries), - csv_to_field=lambda c, v: setattr(c, '_publisher_countries', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.FieldPath, - field_to_csv=lambda c: bulk_str(c.field_path), - csv_to_field=lambda c, v: setattr(c, '_field_path', v if v else None) - ), - ] - - def can_enclose_in_multiline_entity(self): - return super(BulkError, self).can_enclose_in_multiline_entity() - - def enclose_in_multiline_entity(self): - return super(BulkError, self).enclose_in_multiline_entity() - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, BulkError._MAPPINGS) - - def read_related_data_from_stream(self, stream_reader): - return super(BulkError, self).read_related_data_from_stream(stream_reader) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.entity.write_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkError._MAPPINGS) - - def write_to_stream(self, stream_writer, exclude_readonly_data): - return super(BulkError, self).write_to_stream(stream_writer, exclude_readonly_data) diff --git a/bingads/v12/bulk/entities/bulk_experiment.py b/bingads/v12/bulk/entities/bulk_experiment.py deleted file mode 100644 index 5790ca9b..00000000 --- a/bingads/v12/bulk/entities/bulk_experiment.py +++ /dev/null @@ -1,97 +0,0 @@ -from bingads.v12.bulk.entities import QualityScoreData, PerformanceData -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.internal.extensions import * - - -class BulkExperiment(_SingleRecordBulkEntity): - """ Represents an experiment. - - This class exposes the property :attr:`experiment` that can be read and written as fields of the Experiment record - in a bulk file. - - For more information, see Experiment at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, experiment=None): - super(BulkExperiment, self).__init__() - self._experiment = experiment - - @property - def experiment(self): - """ The experiment. - """ - return self._experiment - - @experiment.setter - def experiment(self, experiment): - self._experiment = experiment - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.experiment.Id), - csv_to_field=lambda c, v: setattr(c.experiment, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: c.experiment.ExperimentStatus, - csv_to_field=lambda c, v: setattr(c.experiment, 'ExperimentStatus', v) - ), - _SimpleBulkMapping( - header=_StringTable.Name, - field_to_csv=lambda c: c.experiment.Name, - csv_to_field=lambda c, v: setattr(c.experiment, 'Name', v) - ), - _SimpleBulkMapping( - header=_StringTable.StartDate, - field_to_csv=lambda c: bulk_date_str(c.experiment.StartDate), - csv_to_field=lambda c, v: setattr(c.experiment, 'StartDate', parse_date(v)) - ), - _SimpleBulkMapping( - header=_StringTable.EndDate, - field_to_csv=lambda c: bulk_date_str(c.experiment.EndDate), - csv_to_field=lambda c, v: setattr(c.experiment, 'EndDate', parse_date(v)) - ), - _SimpleBulkMapping( - header=_StringTable.TrafficSplitPercent, - field_to_csv=lambda c: bulk_str(c.experiment.TrafficSplitPercent), - csv_to_field=lambda c, v: setattr(c.experiment, 'TrafficSplitPercent', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.BaseCampaignId, - field_to_csv=lambda c: bulk_str(c.experiment.BaseCampaignId), - csv_to_field=lambda c, v: setattr(c.experiment, 'BaseCampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ExperimentCampaignId, - field_to_csv=lambda c: bulk_str(c.experiment.ExperimentCampaignId), - csv_to_field=lambda c, v: setattr(c.experiment, 'ExperimentCampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.ExperimentType, - field_to_csv=lambda c: c.experiment.ExperimentType, - csv_to_field=lambda c, v: setattr(c.experiment, 'ExperimentType', v) - ) - ] - - def process_mappings_from_row_values(self, row_values): - self.experiment = _CAMPAIGN_OBJECT_FACTORY_V12.create('Experiment') - row_values.convert_to_entity(self, BulkExperiment._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._experiment, 'Experiment') - self.convert_to_values(row_values, BulkExperiment._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkExperiment, self).read_additional_data(stream_reader) \ No newline at end of file diff --git a/bingads/v12/bulk/entities/bulk_keyword.py b/bingads/v12/bulk/entities/bulk_keyword.py deleted file mode 100644 index d4dc4d01..00000000 --- a/bingads/v12/bulk/entities/bulk_keyword.py +++ /dev/null @@ -1,312 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.bulk.entities import * -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _ComplexBulkMapping -from bingads.v12.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. - - This class exposes the :attr:`keyword` 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, ad_group_id=None, campaign_name=None, ad_group_name=None, keyword=None): - super(BulkKeyword, self).__init__() - self._ad_group_id = ad_group_id - self._keyword = keyword - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - self._performance_data = None - self._quality_score_data = None - self._bid_suggestions = None - - @property - def ad_group_id(self): - """ The identifier of the ad group that contains the keyword. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._ad_group_id - - @ad_group_id.setter - def ad_group_id(self, ad_group_id): - self._ad_group_id = ad_group_id - - @property - def keyword(self): - """ Defines a keyword within an ad group. - - See Keyword at https://docs.microsoft.com/en-us/bingads/campaign-management-service/keyword?view=bingads-12 - """ - - return self._keyword - - @keyword.setter - def keyword(self, keyword): - self._keyword = keyword - - @property - def campaign_name(self): - """ The name of the campaign that contains the keyword. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the ad group that contains the keyword. - - Corresponds to the 'Ad Group' field in the bulk file. - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def quality_score_data(self): - """ The quality score data for the keyword. - - :rtype: QualityScoreData - """ - - return self._quality_score_data - - @property - def performance_data(self): - """ The historical performance data for the keyword. - - :rtype: PerformanceData - """ - - return self._performance_data - - @property - def bid_suggestions(self): - """ The bid suggestion data for the keyword. - - :rtype: BidSuggestionData - """ - - return self._bid_suggestions - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: bulk_str(c.keyword.Status), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Status', - v if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Id', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.ad_group_id), - csv_to_field=lambda c, v: setattr( - c, - '_ad_group_id', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, '_campaign_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v) - ), - _SimpleBulkMapping( - header=_StringTable.Keyword, - field_to_csv=lambda c: c.keyword.Text, - csv_to_field=lambda c, v: setattr(c.keyword, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.EditorialStatus, - field_to_csv=lambda c: bulk_str(c.keyword.EditorialStatus), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'EditorialStatus', - v if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.MatchType, - field_to_csv=lambda c: bulk_str(c.keyword.MatchType), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'MatchType', - v if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.DestinationUrl, - field_to_csv=lambda c: bulk_optional_str(c.keyword.DestinationUrl, c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'DestinationUrl', - v if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.Bid, - field_to_csv=lambda c: keyword_bid_bulk_str(c.keyword.Bid, c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Bid', - parse_keyword_bid(v) - ) - ), - _SimpleBulkMapping( - header=_StringTable.Param1, - field_to_csv=lambda c: bulk_optional_str(c.keyword.Param1, c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Param1', - v if v else '' - ) - ), - _SimpleBulkMapping( - header=_StringTable.Param2, - field_to_csv=lambda c: bulk_optional_str(c.keyword.Param2, c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Param2', - v if v else '' - ) - ), - _SimpleBulkMapping( - header=_StringTable.Param3, - field_to_csv=lambda c: bulk_optional_str(c.keyword.Param3, c.keyword.Id), - csv_to_field=lambda c, v: setattr( - c.keyword, - 'Param3', - v if v else '' - ) - ), - _SimpleBulkMapping( - header=_StringTable.FinalUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalUrls, c.keyword.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.FinalMobileUrl, - field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalMobileUrls, c.keyword.Id), - csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalMobileUrls, v) - ), - _SimpleBulkMapping( - header=_StringTable.TrackingTemplate, - field_to_csv=lambda c: bulk_str(c.keyword.TrackingUrlTemplate), - csv_to_field=lambda c, v: setattr(c.keyword, 'TrackingUrlTemplate', v if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CustomParameter, - field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.keyword), - csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.keyword, v) - ), - _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme), - _SimpleBulkMapping( - header=_StringTable.FinalUrlSuffix, - field_to_csv=lambda c: bulk_optional_str(c.keyword.FinalUrlSuffix, c.keyword.Id), - csv_to_field=lambda c, v: setattr(c.keyword, 'FinalUrlSuffix', v) - ), - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._keyword, 'keyword') - self.convert_to_values(row_values, BulkKeyword._MAPPINGS) - if not exclude_readonly_data: - QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values) - PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values) - - def process_mappings_from_row_values(self, row_values): - self._keyword = _CAMPAIGN_OBJECT_FACTORY_V12.create('Keyword') - row_values.convert_to_entity(self, BulkKeyword._MAPPINGS) - self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values) - self._performance_data = PerformanceData.read_from_row_values_or_null(row_values) - - def read_additional_data(self, stream_reader): - success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion) - - while success: - if self._bid_suggestions is None: - self._bid_suggestions = BidSuggestionData() - - if isinstance(next_bid_suggestion, BulkKeywordBestPositionBid): - self._bid_suggestions.best_position = next_bid_suggestion - elif isinstance(next_bid_suggestion, BulkKeywordMainLineBid): - self._bid_suggestions.main_line = next_bid_suggestion - elif isinstance(next_bid_suggestion, BulkKeywordFirstPageBid): - self._bid_suggestions.first_page = next_bid_suggestion - - success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion) - - def write_additional_data(self, row_writer): - if self.bid_suggestions is not None: - BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.best_position, row_writer) - BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.main_line, row_writer) - BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.first_page, row_writer) diff --git a/bingads/v12/bulk/entities/bulk_negative_keywords.py b/bingads/v12/bulk/entities/bulk_negative_keywords.py deleted file mode 100644 index 031ccde2..00000000 --- a/bingads/v12/bulk/entities/bulk_negative_keywords.py +++ /dev/null @@ -1,482 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _DynamicColumnNameMapping -from bingads.v12.internal.extensions import bulk_str - - -class _BulkNegativeKeyword(_SingleRecordBulkEntity): - """ The base class for all bulk negative keywords. - - Either assigned individually to a campaign or ad group entity, or shared in a negative keyword list. - - *See also:* - - * :class:`.BulkAdGroupNegativeKeyword` - * :class:`.BulkCampaignNegativeKeyword` - * :class:`.BulkSharedNegativeKeyword` - """ - - def __init__(self, status=None, negative_keyword=None, parent_id=None): - super(_BulkNegativeKeyword, self).__init__() - - self._negative_keyword = negative_keyword - self._status = status - self._parent_id = parent_id - - @property - def status(self): - """ The status of the negative keyword association. - - The value is 'Active' if the negative keyword is assigned to the parent entity. - The value is 'Deleted' if the negative keyword is removed from the parent entity, - or should be removed in a subsequent upload operation. - :rtype: str - """ - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def negative_keyword(self): - """ Defines a negative keyword with match type. """ - - return self._negative_keyword - - @negative_keyword.setter - def negative_keyword(self, negative_keyword): - self._negative_keyword = negative_keyword - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_keyword.Id), - csv_to_field=lambda c, v: setattr(c.negative_keyword, 'Id', int(v) if v else None) - ), - _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.ParentId, - field_to_csv=lambda c: bulk_str(c._parent_id), - csv_to_field=lambda c, v: setattr(c, '_parent_id', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Keyword, - field_to_csv=lambda c: c.negative_keyword.Text, - csv_to_field=lambda c, v: setattr(c.negative_keyword, 'Text', v) - ), - _SimpleBulkMapping( - header=_StringTable.MatchType, - field_to_csv=lambda c: bulk_str(c.negative_keyword.MatchType), - csv_to_field=lambda c, v: setattr(c.negative_keyword, 'MatchType', v) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._negative_keyword, 'negative_keyword') - self.convert_to_values(row_values, _BulkNegativeKeyword._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_keyword = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeKeyword') - self._negative_keyword.Type = 'NegativeKeyword' - row_values.convert_to_entity(self, _BulkNegativeKeyword._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(_BulkNegativeKeyword, self).read_additional_data(stream_reader) - - -class _BulkEntityNegativeKeyword(_BulkNegativeKeyword): - """ This base class for all bulk negative keywords that are assigned individually to a campaign or ad group entity. - - *See also:* - - * :class:`.BulkAdGroupNegativeKeyword` - * :class:`.BulkCampaignNegativeKeyword` - """ - - def __init__(self, - status=None, - negative_keyword=None, - parent_id=None, - entity_name=None): - super(_BulkEntityNegativeKeyword, self).__init__( - status, - negative_keyword, - parent_id, - ) - self._entity_name = entity_name - - @property - def _entity_column_name(self): - raise NotImplementedError() - - _MAPPINGS = [ - _DynamicColumnNameMapping( - header_func=lambda c: c._entity_column_name, - field_to_csv=lambda c: c._entity_name, - csv_to_field=lambda c, v: setattr(c, '_entity_name', v)) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - super(_BulkEntityNegativeKeyword, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, _BulkEntityNegativeKeyword._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - super(_BulkEntityNegativeKeyword, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, _BulkEntityNegativeKeyword._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(_BulkEntityNegativeKeyword, self).read_additional_data(stream_reader) - - -class BulkAdGroupNegativeKeyword(_BulkEntityNegativeKeyword): - """ Represents a negative keyword that is assigned to a ad group. Each negative keyword can be read or written in a bulk file. - - This class exposes the :attr:`.BulkNegativeKeyword.negative_keyword` property that can be read and written as - fields of the Ad Group Negative Keyword record in a bulk file. - - For more information, see Ad Group Negative Keyword at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - status=None, - negative_keyword=None, - ad_group_id=None, - ad_group_name=None, - campaign_name=None): - super(BulkAdGroupNegativeKeyword, self).__init__( - status, - negative_keyword, - ad_group_id, - ad_group_name, - ) - self._campaign_name = campaign_name - - @property - def campaign_name(self): - """ The name of the campaign that the negative keyword is assigned. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_id(self): - """ Corresponds to the 'Parent Id' field in the bulk file. - - :return: The identifier of the ad group that the negative keyword is assigned. - :rtype: int - """ - - return self._parent_id - - @ad_group_id.setter - def ad_group_id(self, value): - self._parent_id = value - - @property - def ad_group_name(self): - """ Corresponds to the 'Ad Group' field in the bulk file. - - :return: The name of the ad group that the negative keyword is assigned. - :rtype: str - """ - - return self._entity_name - - @ad_group_name.setter - def ad_group_name(self, value): - self._entity_name = value - - @property - def _entity_column_name(self): - return _StringTable.AdGroup - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - super(BulkAdGroupNegativeKeyword, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkAdGroupNegativeKeyword._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - super(BulkAdGroupNegativeKeyword, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkAdGroupNegativeKeyword._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeKeyword, self).read_additional_data(stream_reader) - - -class BulkCampaignNegativeKeyword(_BulkEntityNegativeKeyword): - """ Represents a negative keyword that is assigned to a campaign. Each negative keyword can be read or written in a bulk file. - - This class exposes the :attr:`BulkNegativeKeyword.negative_keyword` property that can be read and written as - fields of the Campaign Negative Keyword record in a bulk file. - - For more information, see Campaign Negative Keyword at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - status=None, - negative_keyword=None, - campaign_id=None, - campaign_name=None): - super(BulkCampaignNegativeKeyword, self).__init__( - status, - negative_keyword, - campaign_id, - campaign_name, - ) - - @property - def campaign_id(self): - """ The identifier of the campaign that the negative keyword is assigned. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._parent_id - - @campaign_id.setter - def campaign_id(self, value): - self._parent_id = value - - @property - def campaign_name(self): - """ The name of the campaign that the negative keyword is assigned. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._entity_name - - @campaign_name.setter - def campaign_name(self, value): - self._entity_name = value - - @property - def _entity_column_name(self): - return _StringTable.Campaign - - -class BulkCampaignNegativeKeywordList(_SingleRecordBulkEntity): - """ Represents a negative keyword list that is assigned to a campaign. Each negative keyword list can be read or written in a bulk file. - - This class exposes the :attr:`BulkCampaignNegativeKeywordList.SharedEntityAssociation` property that can be read - and written as fields of the Campaign Negative Keyword List Association record in a bulk file. - - For more information, see Campaign Negative Keyword List Association at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, status=None, shared_entity_association=None): - super(BulkCampaignNegativeKeywordList, self).__init__() - - self._shared_entity_association = shared_entity_association - self._status = status - - @property - def status(self): - """ The status of the negative keyword list association. - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def shared_entity_association(self): - """ The campaign and negative keyword list identifiers. - - see Campaign Negative Keyword List Association at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._shared_entity_association - - @shared_entity_association.setter - def shared_entity_association(self, shared_entity_association): - self._shared_entity_association = shared_entity_association - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Status, - field_to_csv=lambda c: 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: bulk_str(c.shared_entity_association.SharedEntityId), - csv_to_field=lambda c, v: setattr(c.shared_entity_association, 'SharedEntityId', int(v)) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.shared_entity_association.EntityId), - csv_to_field=lambda c, v: setattr(c.shared_entity_association, 'EntityId', int(v)) - ), - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._shared_entity_association, 'shared_entity_association') - self.convert_to_values(row_values, BulkCampaignNegativeKeywordList._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._shared_entity_association = _CAMPAIGN_OBJECT_FACTORY_V12.create('SharedEntityAssociation') - self._shared_entity_association.EntityType = 'Campaign' - self._shared_entity_association.SharedEntityType = 'NegativeKeywordList' - row_values.convert_to_entity(self, BulkCampaignNegativeKeywordList._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignNegativeKeywordList, self).read_additional_data(stream_reader) - - -class BulkNegativeKeywordList(_SingleRecordBulkEntity): - """ Represents a negative keyword list that can be read or written in a bulk file. - - This class exposes the :attr:`.BulkNegativeKeywordList.negative_keyword_list` property that can be read and - written as fields of the Negative Keyword List record in a bulk file. - - For more information, see Negative Keyword List at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, status=None, negative_keyword_list=None): - super(BulkNegativeKeywordList, self).__init__() - - self._status = status - self._negative_keyword_list = negative_keyword_list - - @property - def negative_keyword_list(self): - """ The negative keyword list. - - see Negative Keyword List at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._negative_keyword_list - - @negative_keyword_list.setter - def negative_keyword_list(self, negative_keyword_list): - self._negative_keyword_list = negative_keyword_list - - @property - def status(self): - """ The status of the negative keyword list. - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_keyword_list.Id), - csv_to_field=lambda c, v: setattr(c.negative_keyword_list, 'Id', int(v) if v else None) - ), - _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.Name, - field_to_csv=lambda c: c.negative_keyword_list.Name, - csv_to_field=lambda c, v: setattr(c.negative_keyword_list, 'Name', v) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._negative_keyword_list, 'negative_keyword_list') - self.convert_to_values(row_values, BulkNegativeKeywordList._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_keyword_list = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeKeywordList') - self._negative_keyword_list.Type = 'NegativeKeywordList' - row_values.convert_to_entity(self, BulkNegativeKeywordList._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkNegativeKeywordList, self).read_additional_data(stream_reader) - - -class BulkSharedNegativeKeyword(_BulkNegativeKeyword): - """ Represents a negative keyword that is shared in a negative keyword list. - - Each shared negative keyword can be read or written in a bulk file. - This class exposes the :attr:`.BulkNegativeKeyword.NegativeKeyword` property that - can be read and written as fields of the Shared Negative Keyword record in a bulk file. - - For more information, see Shared Negative Keyword at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, status=None, negative_keyword=None, negative_keyword_list_id=None): - super(BulkSharedNegativeKeyword, self).__init__(status, negative_keyword, negative_keyword_list_id) - - @property - def negative_keyword_list_id(self): - return self._parent_id - - @negative_keyword_list_id.setter - def negative_keyword_list_id(self, value): - self._parent_id = value diff --git a/bingads/v12/bulk/entities/bulk_negative_sites.py b/bingads/v12/bulk/entities/bulk_negative_sites.py deleted file mode 100644 index a278144e..00000000 --- a/bingads/v12/bulk/entities/bulk_negative_sites.py +++ /dev/null @@ -1,761 +0,0 @@ -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - -from bingads.v12.internal.bulk.entities.bulk_entity_identifier import _BulkEntityIdentifier -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping, _DynamicColumnNameMapping -from bingads.v12.internal.bulk.entities.multi_record_bulk_entity import _MultiRecordBulkEntity -from bingads.v12.internal.extensions import bulk_str - - -class _BulkNegativeSite(_SingleRecordBulkEntity): - """ This abstract base class for the bulk negative sites that are assigned individually to a campaign or ad group entity. - - *See also:* - - * :class:`.BulkAdGroupNegativeSite` - * :class:`.BulkCampaignNegativeSite` - """ - - def __init__(self, identifier, website=None): - super(_BulkNegativeSite, self).__init__() - - self._identifier = identifier - self._website = website - - @property - def website(self): - """ The URL of a website on which you do not want your ads displayed. - - Corresponds to the 'Website' field in the bulk file. - - :rtype: str - """ - - return self._website - - @website.setter - def website(self, website): - self._website = website - - @property - def status(self): - """ The status of the negative site association. - - :rtype: str - """ - - return self._identifier.status - - @status.setter - def status(self, value): - self._identifier.status = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Website, - field_to_csv=lambda c: c.website, - csv_to_field=lambda c, v: setattr(c, 'website', v) - ), - ] - - def process_mappings_from_row_values(self, row_values): - self._identifier.read_from_row_values(row_values) - row_values.convert_to_entity(self, _BulkNegativeSite._MAPPINGS) - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._identifier.write_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, _BulkNegativeSite._MAPPINGS) - - @property - def can_enclose_in_multiline_entity(self): - return True - - def enclose_in_multiline_entity(self): - return self.create_negative_sites_with_this_negative_site() - - def create_negative_sites_with_this_negative_site(self): - raise NotImplementedError() - - def read_additional_data(self, stream_reader): - super(_BulkNegativeSite, self).read_additional_data(stream_reader) - - -class BulkAdGroupNegativeSite(_BulkNegativeSite): - """ Represents a negative site that is assigned to an ad group. Each negative site can be read or written in a bulk file. - - This class exposes properties that can be read and written as fields of the Ad Group Negative Site record in a bulk file. - - For more information, see Ad Group Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - - One :class:`.BulkAdGroupNegativeSites` exposes a read only list of :class:`.BulkAdGroupNegativeSite`. Each - :class:`.BulkAdGroupNegativeSite` instance corresponds to one Ad Group Negative Site record in the bulk file. If you - upload a :class:`.BulkAdGroupNegativeSites`, then you are effectively replacing any existing negative sites - assigned to the ad group. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - status=None, - ad_group_id=None, - ad_group_name=None, - campaign_name=None, - website=None): - super(BulkAdGroupNegativeSite, self).__init__( - _BulkAdGroupNegativeSitesIdentifier( - status=status, - ad_group_id=ad_group_id, - ad_group_name=ad_group_name, - campaign_name=campaign_name, - ), - website=website - ) - - @property - def ad_group_id(self): - """ The identifier of the ad group that the negative site is assigned. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._identifier.ad_group_id - - @ad_group_id.setter - def ad_group_id(self, value): - self._identifier.ad_group_id = value - - @property - def ad_group_name(self): - """ The name of the ad group that the negative site is assigned. - - Corresponds to the 'Ad Group' field in the bulk file. - - :rtype: str - """ - - return self._identifier.ad_group_name - - @ad_group_name.setter - def ad_group_name(self, value): - self._identifier.ad_group_name = value - - @property - def campaign_name(self): - """ The name of the ad group that the negative site is assigned. - - Corresponds to the 'Ad Group' field in the bulk file. - - :rtype: str - """ - - return self._identifier.campaign_name - - @campaign_name.setter - def campaign_name(self, value): - self._identifier.campaign_name = value - - def create_negative_sites_with_this_negative_site(self): - return BulkAdGroupNegativeSites(site=self) - - -class BulkCampaignNegativeSite(_BulkNegativeSite): - """ Represents a negative site that is assigned to an campaign. Each negative site can be read or written in a bulk file. - - This class exposes properties that can be read and written as fields of the Campaign Negative Site record in a bulk file. - - For more information, see Campaign Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - - One :class:`.BulkCampaignNegativeSites` exposes a read only list of :class:`.BulkCampaignNegativeSite`. Each - :class:`.BulkCampaignNegativeSite` instance corresponds to one Campaign Negative Site record in the bulk file. If you - upload a :class:`.BulkCampaignNegativeSites`, then you are effectively replacing any existing negative sites - assigned to the campaign. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - status=None, - campaign_id=None, - campaign_name=None, - website=None): - super(BulkCampaignNegativeSite, self).__init__( - _BulkCampaignNegativeSitesIdentifier( - status=status, - campaign_id=campaign_id, - campaign_name=campaign_name - ), - website=website - ) - - @property - def campaign_id(self): - """ The identifier of the campaign that the negative site is assigned. - - Corresponds to the 'Parent Id' field in the bulk file. - - :rtype: int - """ - - return self._identifier.campaign_id - - @campaign_id.setter - def campaign_id(self, value): - self._identifier.campaign_id = value - - @property - def campaign_name(self): - """ The name of the campaign that the negative site is assigned. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - return self._identifier.campaign_name - - @campaign_name.setter - def campaign_name(self, value): - self._identifier.campaign_name = value - - def create_negative_sites_with_this_negative_site(self): - return BulkCampaignNegativeSites(site=self) - - -class _BulkNegativeSites(_MultiRecordBulkEntity): - """ This abstract base class for the bulk negative sites that assigned in sets to a campaign or ad group entity. """ - - def __init__(self, status=None, site=None, identifier=None): - super(_BulkNegativeSites, self).__init__() - - self._bulk_negative_sites = [] - self._first_row_identifier = None - self._has_delete_all_row = None - - self._site = site - self._identifier = identifier - - if self._site and self._identifier: - raise ValueError('Conflicting keyword arguments of site and identifier provided') - - if self._site: - if not isinstance(self._site, self.site_class): - raise ValueError('Negative site object provided is not of type: {0}'.format(self.site_class.__name__)) - self._bulk_negative_sites.append(self._site) - self._identifier = self._site._identifier - - if self._identifier: - if not isinstance(self._identifier, self.identifier_class): - raise ValueError( - 'Negative site object provided is not of type: {0}'.format(self.identifier_class.__name__)) - self._first_row_identifier = self._identifier - self._has_delete_all_row = self._identifier.is_delete_row - - self._status = status - - @property - def status(self): - """ The status of the negative site association. - - :rtype: str - """ - - return self._status - - @status.setter - def status(self, status): - self._status = status - - @property - def negative_sites(self): - return self._bulk_negative_sites - - @property - def child_entities(self): - return self.negative_sites - - def _create_identifier(self): - raise NotImplementedError() - - def _validate_properties_not_null(self): - raise NotImplementedError() - - def write_to_stream(self, row_writer, exclude_readonly_data): - self._validate_properties_not_null() - - delete_row = self._create_identifier() - delete_row._status = 'Deleted' - row_writer.write_object_row(delete_row, exclude_readonly_data) - - if self._status == 'Deleted': - return - - for site in self.convert_api_to_bulk_negative_sites(): - site.write_to_stream(row_writer, exclude_readonly_data) - - def convert_api_to_bulk_negative_sites(self): - raise NotImplementedError() - - def reconstruct_api_objects(self): - raise NotImplementedError() - - @property - def site_class(self): - raise NotImplementedError() - - @property - def identifier_class(self): - raise NotImplementedError() - - def read_related_data_from_stream(self, stream_reader): - has_more_rows = True - while has_more_rows: - site_success, site = stream_reader.try_read( - self.site_class, - lambda x: x._identifier == self._first_row_identifier - ) - if site_success: - self._bulk_negative_sites.append(site) - else: - identifier_success, identifier = stream_reader.try_read( - self.identifier_class, - lambda x: x == self._first_row_identifier - ) - if identifier_success: - if identifier.is_delete_row: - self._has_delete_all_row = True - else: - has_more_rows = False - - self.reconstruct_api_objects() - self._status = 'Active' if self._bulk_negative_sites else 'Deleted' - - @property - def all_children_are_present(self): - return self._has_delete_all_row - - -class BulkAdGroupNegativeSites(_BulkNegativeSites): - """ Represents one or more negative sites that are assigned to an ad group. Each negative site can be read or written in a bulk file. - - This class exposes properties that can be read and written as fields of the Ad Group Negative Site record in a bulk file. - - For more information, see Ad Group Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - - One :class:`.BulkAdGroupNegativeSites` has one or more :class:`.BulkAdGroupNegativeSite`. Each :class:`.BulkAdGroupNegativeSite` instance - corresponds to one Ad Group Negative Site record in the bulk file. If you upload a :class:`.BulkAdGroupNegativeSites`, - then you are effectively replacing any existing negative sites assigned to the ad group. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - ad_group_negative_sites=None, - ad_group_name=None, - campaign_name=None, - status=None, - site=None, - identifier=None): - super(BulkAdGroupNegativeSites, self).__init__( - status=status, - site=site, - identifier=identifier, - ) - - self._ad_group_negative_sites = ad_group_negative_sites - self._ad_group_name = ad_group_name - self._campaign_name = campaign_name - - if self._identifier: - self.set_data_from_identifier(self._identifier) - - @property - def ad_group_negative_sites(self): - """ The AdGroupNegativeSites Data Object of the Campaign Management Service. - - subset of AdGroupNegativeSites properties are available in the Ad Group Negative Site record. - For more information, see Ad Group Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - return self._ad_group_negative_sites - - @ad_group_negative_sites.setter - def ad_group_negative_sites(self, ad_group_negative_sites): - self._ad_group_negative_sites = ad_group_negative_sites - - @property - def ad_group_name(self): - """ The name of the ad group that the negative site is assigned. - - Corresponds to the 'Ad Group' field in the bulk file. - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - @property - def campaign_name(self): - """ The name of the campaign that the negative site is assigned. - - Corresponds to the 'Campaign' field in the bulk file. - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def set_data_from_identifier(self, identifier): - self._ad_group_negative_sites = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdGroupNegativeSites') - self._ad_group_negative_sites.AdGroupId = identifier.ad_group_id - self._ad_group_name = identifier.ad_group_name - self._campaign_name = identifier.campaign_name - - def convert_api_to_bulk_negative_sites(self): - self._validate_list_not_null_or_empty( - self._ad_group_negative_sites.NegativeSites, - self._ad_group_negative_sites.NegativeSites.string, - 'ad_group_negative_sites.negative_sites' - ) - - def convert_api_to_bulk_negative_site(website): - bulk_ad_group_negative_site = BulkAdGroupNegativeSite() - bulk_ad_group_negative_site.ad_group_id = self._ad_group_negative_sites.AdGroupId - bulk_ad_group_negative_site.ad_group_name = self._ad_group_name - bulk_ad_group_negative_site.campaign_name = self._campaign_name - bulk_ad_group_negative_site._website = website - return bulk_ad_group_negative_site - - return map(convert_api_to_bulk_negative_site, self._ad_group_negative_sites.NegativeSites.string) - - def reconstruct_api_objects(self): - self._ad_group_negative_sites.NegativeSites.string = list(map(lambda x: x.website, self.negative_sites)) - - def _create_identifier(self): - return _BulkAdGroupNegativeSitesIdentifier( - ad_group_id=self._ad_group_negative_sites.AdGroupId, - ad_group_name=self._ad_group_name, - campaign_name=self.campaign_name - ) - - def _validate_properties_not_null(self): - self._validate_property_not_null(self._ad_group_negative_sites, 'ad_group_negative_sites') - - @property - def identifier_class(self): - return _BulkAdGroupNegativeSitesIdentifier - - @property - def site_class(self): - return BulkAdGroupNegativeSite - - -class BulkCampaignNegativeSites(_BulkNegativeSites): - """ Represents one or more negative sites that are assigned to an campaign. Each negative site can be read or written in a bulk file. - - This class exposes properties that can be read and written as fields of the Campaign Negative Site record in a bulk file. - - For more information, see Campaign Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - - One :class:`.BulkCampaignNegativeSites` has one or more :class:`.BulkCampaignNegativeSite`. Each :class:`.BulkCampaignNegativeSite` instance - corresponds to one Campaign Negative Site record in the bulk file. If you upload a :class:`.BulkCampaignNegativeSites`, - then you are effectively replacing any existing negative sites assigned to the campaign. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - campaign_negative_sites=None, - campaign_name=None, - status=None, - site=None, - identifier=None): - super(BulkCampaignNegativeSites, self).__init__( - status=status, - site=site, - identifier=identifier - ) - - self._campaign_negative_sites = campaign_negative_sites - self._campaign_name = campaign_name - - if self._identifier: - self.set_data_from_identifier(self._identifier) - - @property - def campaign_negative_sites(self): - """ The CampaignNegativeSites Data Object of the Campaign Management Service. - - A subset of CampaignNegativeSites properties are available in the Campaign Negative Site record. - For more information, see Campaign Negative Site at https://go.microsoft.com/fwlink/?linkid=846127. - - """ - - return self._campaign_negative_sites - - @campaign_negative_sites.setter - def campaign_negative_sites(self, campaign_negative_sites): - self._campaign_negative_sites = campaign_negative_sites - - @property - def campaign_name(self): - """ The name of the campaign that the negative site is assigned. - - Corresponds to the 'Campaign' field in the bulk file. - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def set_data_from_identifier(self, identifier): - self._campaign_negative_sites = _CAMPAIGN_OBJECT_FACTORY_V12.create('CampaignNegativeSites') - self.campaign_negative_sites.CampaignId = identifier.campaign_id - self._campaign_name = identifier.campaign_name - - def convert_api_to_bulk_negative_sites(self): - self._validate_list_not_null_or_empty( - self._campaign_negative_sites.NegativeSites, - self._campaign_negative_sites.NegativeSites.string, - 'campaign_negative_sites.negative_sites' - ) - - def convert_api_to_bulk_negative_site(website): - bulk_campaign_negative_site = BulkCampaignNegativeSite() - bulk_campaign_negative_site.campaign_id = self._campaign_negative_sites.CampaignId - bulk_campaign_negative_site.campaign_name = self._campaign_name - bulk_campaign_negative_site._website = website - return bulk_campaign_negative_site - - return map(convert_api_to_bulk_negative_site, self._campaign_negative_sites.NegativeSites.string) - - def reconstruct_api_objects(self): - self._campaign_negative_sites.NegativeSites.string = list(map(lambda x: x.website, self.negative_sites)) - - def _create_identifier(self): - return _BulkCampaignNegativeSitesIdentifier( - campaign_id=self._campaign_negative_sites.CampaignId, - campaign_name=self._campaign_name - ) - - def _validate_properties_not_null(self): - self._validate_property_not_null(self._campaign_negative_sites, 'campaign_negative_sites') - - @property - def identifier_class(self): - return _BulkCampaignNegativeSitesIdentifier - - @property - def site_class(self): - return BulkCampaignNegativeSite - - -class _BulkNegativeSiteIdentifier(_BulkEntityIdentifier): - def __init__(self, status=None, entity_id=None, entity_name=None): - self._status = status - self._entity_id = entity_id - self._entity_name = entity_name - - @property - def status(self): - return self._status - - @property - def entity_id(self): - return self._entity_id - - @property - def entity_name(self): - return self._entity_name - - @property - def _parent_column_name(self): - raise NotImplementedError() - - _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.ParentId, - field_to_csv=lambda c: None if c._entity_id == 0 else bulk_str(c._entity_id), - csv_to_field=lambda c, v: setattr(c, '_entity_id', int(v) if v else 0) - ), - _DynamicColumnNameMapping( - header_func=lambda c: c._parent_column_name, - field_to_csv=lambda c: c._entity_name, - csv_to_field=lambda c, v: setattr(c, '_entity_name', v) - ) - ] - - @property - def is_delete_row(self): - return self._status == 'Deleted' - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, _BulkNegativeSiteIdentifier._MAPPINGS) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, _BulkNegativeSiteIdentifier._MAPPINGS) - - -class _BulkCampaignNegativeSitesIdentifier(_BulkNegativeSiteIdentifier): - def __init__(self, status=None, campaign_id=None, campaign_name=None): - super(_BulkCampaignNegativeSitesIdentifier, self).__init__( - status, - campaign_id, - campaign_name, - ) - - def __eq__(self, other): - is_name_not_empty = ( - self.campaign_name is not None and - len(self.campaign_name) > 0 - ) - return ( - type(self) == type(other) and - ( - self.campaign_id == other.campaign_id or - ( - is_name_not_empty and - self.campaign_name == other.campaign_name - ) - ) - ) - - @property - def campaign_id(self): - return self._entity_id - - @campaign_id.setter - def campaign_id(self, value): - self._entity_id = value - - @property - def campaign_name(self): - return self._entity_name - - @campaign_name.setter - def campaign_name(self, value): - self._entity_name = value - - def _create_entity_with_this_identifier(self): - return BulkCampaignNegativeSites(identifier=self) - - @property - def _parent_column_name(self): - return _StringTable.Campaign - - -class _BulkAdGroupNegativeSitesIdentifier(_BulkNegativeSiteIdentifier): - def __init__(self, - status=None, - ad_group_id=None, - ad_group_name=None, - campaign_name=None): - super(_BulkAdGroupNegativeSitesIdentifier, self).__init__( - status, - ad_group_id, - ad_group_name, - ) - self._campaign_name = campaign_name - - def __eq__(self, other): - is_name_not_empty = ( - self.campaign_name is not None and - len(self.campaign_name) > 0 and - self.ad_group_name is not None and - len(self.ad_group_name) > 0 - ) - return ( - type(self) == type(other) and - ( - self.ad_group_id == other.ad_group_id or - ( - is_name_not_empty and - self.campaign_name == other.campaign_name and - self.ad_group_name == other.ad_group_name - ) - ) - ) - - @property - def ad_group_id(self): - return self._entity_id - - @ad_group_id.setter - def ad_group_id(self, value): - self._entity_id = value - - @property - def ad_group_name(self): - return self._entity_name - - @ad_group_name.setter - def ad_group_name(self, value): - self._entity_name = value - - @property - def campaign_name(self): - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - ] - - def read_from_row_values(self, row_values): - super(_BulkAdGroupNegativeSitesIdentifier, self).read_from_row_values(row_values) - row_values.convert_to_entity(self, _BulkAdGroupNegativeSitesIdentifier._MAPPINGS) - - def write_to_row_values(self, row_values, exclude_readonly_data): - super(_BulkAdGroupNegativeSitesIdentifier, self).write_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, _BulkAdGroupNegativeSitesIdentifier._MAPPINGS) - - def _create_entity_with_this_identifier(self): - return BulkAdGroupNegativeSites(identifier=self) - - @property - def _parent_column_name(self): - return _StringTable.AdGroup diff --git a/bingads/v12/bulk/entities/bulk_offline_conversion.py b/bingads/v12/bulk/entities/bulk_offline_conversion.py deleted file mode 100644 index 6cf376af..00000000 --- a/bingads/v12/bulk/entities/bulk_offline_conversion.py +++ /dev/null @@ -1,97 +0,0 @@ -from __future__ import print_function -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.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_V12.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) diff --git a/bingads/v12/bulk/entities/common.py b/bingads/v12/bulk/entities/common.py deleted file mode 100644 index 4bd4323d..00000000 --- a/bingads/v12/bulk/entities/common.py +++ /dev/null @@ -1,360 +0,0 @@ -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.bulk_object import _BulkObject -from bingads.v12.internal.extensions import * - -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 - - -class _ProductConditionHelper: - def __init__(self): - pass - - MAX_NUMBER_OF_CONDITIONS = 8 - - @staticmethod - def add_conditions_from_row_values(row_values, conditions): - """ - - :param row_values: - :type row_values: _RowValues - :param conditions: - :type conditions: list[ProductCondition] - :rtype: None - """ - - condition_header_prefix = _StringTable.ProductCondition1[:-1] - value_header_prefix = _StringTable.ProductValue1[:-1] - - for i in range(1, _ProductConditionHelper.MAX_NUMBER_OF_CONDITIONS + 1): - condition_success, product_condition = row_values.try_get_value(condition_header_prefix + str(i)) - value_success, product_value = row_values.try_get_value(value_header_prefix + str(i)) - - if product_condition and product_value: - condition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductCondition') - condition.Operand = product_condition - condition.Attribute = product_value - conditions.append(condition) - - @staticmethod - def add_row_values_from_conditions(conditions, row_values): - """ - - :param conditions: - :type conditions: list[ProductCondition] - :param row_values: - :type row_values: _RowValues - :rtype: None - """ - - condition_header_prefix = _StringTable.ProductCondition1[:-1] - value_header_prefix = _StringTable.ProductValue1[:-1] - - for i in range(1, len(conditions) + 1): - row_values[condition_header_prefix + str(i)] = conditions[i - 1].Operand - row_values[value_header_prefix + str(i)] = conditions[i - 1].Attribute - - -class PerformanceData(_BulkObject): - """ Represents a subset of the fields available in bulk records that support historical performance data. - - For example :class:`.BulkKeyword`. - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - def __init__(self): - self._spend = None - self._impressions = None - self._clicks = None - self._click_through_rate = None - self._average_cost_per_click = None - self._average_cost_per_thousand_impressions = None - self._average_position = None - self._conversions = None - self._cost_per_conversion = None - - @property - def spend(self): - """ Corresponds to the 'Spend' field in the bulk file. - - :rtype: float - """ - - return self._spend - - @property - def impressions(self): - """ Corresponds to the 'Impressions' field in the bulk file. - - :rtype: int - """ - - return self._impressions - - @property - def clicks(self): - """ Corresponds to the 'Clicks' field in the bulk file. - - :rtype: int - """ - - return self._clicks - - @property - def click_through_rate(self): - """ Corresponds to the 'CTR' field in the bulk file. - - :rtype: float - """ - - return self._click_through_rate - - @property - def average_cost_per_click(self): - """ Corresponds to the 'Avg CPC' field in the bulk file. - - :rtype: float - """ - - return self._average_cost_per_click - - @property - def average_cost_per_thousand_impressions(self): - """ Corresponds to the 'Avg CPM' field in the bulk file. - - :rtype: float - """ - - return self._average_cost_per_thousand_impressions - - @property - def average_position(self): - """ Corresponds to the 'Avg position' field in the bulk file. - - :rtype: float - """ - - return self._average_position - - @property - def conversions(self): - """ Corresponds to the 'Conversions' field in the bulk file. - - :rtype: int - """ - - return self._conversions - - @property - def cost_per_conversion(self): - """ Corresponds to the 'CPA' field in the bulk file. - - :rtype: float - """ - - return self._cost_per_conversion - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Spend, - field_to_csv=lambda c: bulk_str(c.spend), - csv_to_field=lambda c, v: setattr(c, '_spend', float(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Impressions, - field_to_csv=lambda c: bulk_str(c.impressions), - csv_to_field=lambda c, v: setattr(c, '_impressions', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Clicks, - field_to_csv=lambda c: bulk_str(c.clicks), - csv_to_field=lambda c, v: setattr(c, '_clicks', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CTR, - field_to_csv=lambda c: bulk_str(c.click_through_rate), - csv_to_field=lambda c, v: setattr(c, '_click_through_rate', float(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AvgCPC, - field_to_csv=lambda c: bulk_str(c.average_cost_per_click), - csv_to_field=lambda c, v: setattr(c, '_average_cost_per_click', float(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.AvgCPM, - field_to_csv=lambda c: bulk_str(c.average_cost_per_thousand_impressions), - csv_to_field=lambda c, v: setattr( - c, - '_average_cost_per_thousand_impressions', - float(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.AvgPosition, - field_to_csv=lambda c: bulk_str(c.average_position), - csv_to_field=lambda c, v: setattr(c, '_average_position', float(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.Conversions, - field_to_csv=lambda c: bulk_str(c.conversions), - csv_to_field=lambda c, v: setattr(c, '_conversions', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.CPA, - field_to_csv=lambda c: bulk_str(c.cost_per_conversion), - csv_to_field=lambda c, v: setattr(c, '_cost_per_conversion', float(v) if v else None) - ) - ] - - @staticmethod - def read_from_row_values_or_null(row_values): - performance_data = PerformanceData() - performance_data.read_from_row_values(row_values) - return performance_data if performance_data.has_any_values else None - - @staticmethod - def write_to_row_values_if_not_null(performance_data, row_values): - if performance_data is not None: - performance_data.write_to_row_values(row_values, False) - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, PerformanceData._MAPPINGS) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, PerformanceData._MAPPINGS) - - @property - def has_any_values(self): - return \ - self.average_cost_per_click \ - or self.average_cost_per_thousand_impressions \ - or self.average_position \ - or self.click_through_rate \ - or self.clicks \ - or self.conversions \ - or self.cost_per_conversion \ - or self.impressions \ - or self.spend - - def write_to_stream(self, row_writer, exclude_readonly_data): - pass - - def read_related_data_from_stream(self, stream_reader): - super(PerformanceData, self).read_related_data_from_stream(stream_reader) - - def enclose_in_multiline_entity(self): - pass - - @property - def can_enclose_in_multiline_entity(self): - return super(PerformanceData, self).can_enclose_in_multiline_entity() - - -class QualityScoreData(_BulkObject): - """ Represents a subset of the fields available in bulk records that support quality score data. - - For example :class:`.BulkKeyword`. For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - def __init__(self): - self._quality_score = None - self._keyword_relevance = None - self._landing_page_relevance = None - self._landing_page_user_experience = None - - @property - def quality_score(self): - """ Corresponds to the 'Quality Score' field in the bulk file. - - :rtype: int - """ - - return self._quality_score - - @property - def keyword_relevance(self): - """ Corresponds to the 'Keyword Relevance' field in the bulk file. - - :rtype: int - """ - - return self._keyword_relevance - - @property - def landing_page_relevance(self): - """ Corresponds to the 'Landing Page Relevance' field in the bulk file. - - :rtype: int - """ - - return self._landing_page_relevance - - @property - def landing_page_user_experience(self): - """ Corresponds to the 'Landing Page User Experience' field in the bulk file. - - :rtype: int - """ - - return self._landing_page_user_experience - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.QualityScore, - field_to_csv=lambda c: bulk_str(c.quality_score), - csv_to_field=lambda c, v: setattr(c, '_quality_score', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.KeywordRelevance, - field_to_csv=lambda c: bulk_str(c.keyword_relevance), - csv_to_field=lambda c, v: setattr(c, '_keyword_relevance', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.LandingPageRelevance, - field_to_csv=lambda c: bulk_str(c.landing_page_relevance), - csv_to_field=lambda c, v: setattr(c, '_landing_page_relevance', int(v) if v else None) - ), - _SimpleBulkMapping( - header=_StringTable.LandingPageUserExperience, - field_to_csv=lambda c: bulk_str(c.landing_page_user_experience), - csv_to_field=lambda c, v: setattr(c, '_landing_page_user_experience', int(v) if v else None) - ), - ] - - @staticmethod - def read_from_row_values_or_null(row_values): - quality_score_data = QualityScoreData() - quality_score_data.read_from_row_values(row_values) - return quality_score_data if quality_score_data.has_any_values else None - - @staticmethod - def write_to_row_values_if_not_null(quality_score_data, row_values): - if quality_score_data is not None: - quality_score_data.write_to_row_values(row_values, False) - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, QualityScoreData._MAPPINGS) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, QualityScoreData._MAPPINGS) - - @property - def has_any_values(self): - return \ - self.quality_score \ - or self.keyword_relevance \ - or self.landing_page_relevance \ - or self.landing_page_user_experience - - def write_to_stream(self, row_writer, exclude_readonly_data): - pass - - def read_related_data_from_stream(self, stream_reader): - super(QualityScoreData, self).read_related_data_from_stream(stream_reader) - - def enclose_in_multiline_entity(self): - pass - - @property - def can_enclose_in_multiline_entity(self): - return super(QualityScoreData, self).can_enclose_in_multiline_entity() diff --git a/bingads/v12/bulk/entities/labels/__init__.py b/bingads/v12/bulk/entities/labels/__init__.py deleted file mode 100644 index 053dc1f5..00000000 --- a/bingads/v12/bulk/entities/labels/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .bulk_label import * -from .bulk_label_associations import * diff --git a/bingads/v12/bulk/entities/labels/bulk_label.py b/bingads/v12/bulk/entities/labels/bulk_label.py deleted file mode 100644 index a86d4ae5..00000000 --- a/bingads/v12/bulk/entities/labels/bulk_label.py +++ /dev/null @@ -1,104 +0,0 @@ -from __future__ import print_function -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.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_V12.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) diff --git a/bingads/v12/bulk/entities/labels/bulk_label_associations.py b/bingads/v12/bulk/entities/labels/bulk_label_associations.py deleted file mode 100644 index 06f0ee95..00000000 --- a/bingads/v12/bulk/entities/labels/bulk_label_associations.py +++ /dev/null @@ -1,380 +0,0 @@ -from __future__ import print_function -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.extensions import * - - -class _BulkLabelAssociation(_SingleRecordBulkEntity): - """ Represents a label association that can be read or written in a bulk file. - - This class exposes the :attr:`label_association` 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_association=None, status=None): - super(_BulkLabelAssociation, self).__init__() - self._label_association = label_association - self._status = status - - @property - def label_association(self): - """ The LabelAssociation Data Object of the Campaign Management Service. - - A subset of Label properties are available in the Ad Group record. - """ - - return self._label_association - - @label_association.setter - def label_association(self, value): - self._label_association = 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_association.LabelId, - csv_to_field=lambda c, v: setattr( - c.label_association, - 'LabelId', - int(v) if v else None - ) - ), - _SimpleBulkMapping( - header=_StringTable.ParentId, - field_to_csv=lambda c: c.label_association.EntityId, - csv_to_field=lambda c, v: setattr( - c.label_association, - 'EntityId', - int(v) if v else None - ) - ), - - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self._label_association, 'label_association') - self.convert_to_values(row_values, _BulkLabelAssociation._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._label_association = _CAMPAIGN_OBJECT_FACTORY_V12.create('LabelAssociation') - row_values.convert_to_entity(self, _BulkLabelAssociation._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(_BulkLabelAssociation, self).read_additional_data(stream_reader) - - -class BulkCampaignLabel(_BulkLabelAssociation): - """ Represents a campaign label. - - Defines an association record between a Campaign and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see Campaign Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None, campaign=None): - super(BulkCampaignLabel, self).__init__(label_association, status) - self._campaign = campaign - - @property - def campaign(self): - """ The campaign name of the Campaign Management Service. - - A subset of Label properties are available in the Ad Group record. - """ - - return self._campaign - - @campaign.setter - def campaign(self, value): - self._campaign = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign, - csv_to_field=lambda c, v: setattr( - c, - 'campaign', - v - ) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - super(BulkCampaignLabel, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkCampaignLabel._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - super(BulkCampaignLabel, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkCampaignLabel._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignLabel, self).read_additional_data(stream_reader) - - -class BulkAdGroupLabel(_BulkLabelAssociation): - """ Represents a AdGroup label. - - Defines an association record between a AdGroup and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see AdGroup Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None, campaign=None, ad_group=None): - super(BulkAdGroupLabel, self).__init__(label_association, status) - self._campaign = campaign - self._ad_group = ad_group - - @property - def campaign(self): - """ The campaign name of the Campaign Management Service. - - A subset of Label properties are available in the Ad Group record. - """ - - return self._campaign - - @campaign.setter - def campaign(self, value): - self._campaign = value - - @property - def ad_group(self): - """ The ad group name of the Campaign Management Service. - - A subset of Label properties are available in the Ad Group record. - """ - - return self._campaign - - @ad_group.setter - def ad_group(self, value): - self._ad_group = value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Campaign, - field_to_csv=lambda c: c.campaign, - csv_to_field=lambda c, v: setattr( - c, - 'campaign', - v - ) - ), - _SimpleBulkMapping( - header=_StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group, - csv_to_field=lambda c, v: setattr( - c, - 'ad_group', - v - ) - ) - ] - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - super(BulkAdGroupLabel, self).process_mappings_to_row_values(row_values, exclude_readonly_data) - self.convert_to_values(row_values, BulkAdGroupLabel._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - super(BulkAdGroupLabel, self).process_mappings_from_row_values(row_values) - row_values.convert_to_entity(self, BulkAdGroupLabel._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupLabel, self).read_additional_data(stream_reader) - - -class BulkKeywordLabel(_BulkLabelAssociation): - """ Represents a Keyword label. - - Defines an association record between a Keyword and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see Keyword Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkKeywordLabel, self).__init__(label_association, status) - - -class BulkAppInstallAdLabel(_BulkLabelAssociation): - """ Represents a AppInstallAd label. - - Defines an association record between a AppInstallAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see AppInstallAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkAppInstallAdLabel, self).__init__(label_association, status) - - -class BulkDynamicSearchAdLabel(_BulkLabelAssociation): - """ Represents a DynamicSearchAd label. - - Defines an association record between a DynamicSearchAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see DynamicSearchAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkDynamicSearchAdLabel, self).__init__(label_association, status) - - -class BulkExpandedTextAdLabel(_BulkLabelAssociation): - """ Represents a ExpandedTextAd label. - - Defines an association record between a ExpandedTextAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see ExpandedTextAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkExpandedTextAdLabel, self).__init__(label_association, status) - - -class BulkProductAdLabel(_BulkLabelAssociation): - """ Represents a ProductAd label. - - Defines an association record between a ProductAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see ProductAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkProductAdLabel, self).__init__(label_association, status) - - -class BulkTextAdLabel(_BulkLabelAssociation): - """ Represents a TextAd label. - - Defines an association record between a TextAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see TextAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkTextAdLabel, self).__init__(label_association, status) - -class BulkResponsiveAdLabel(_BulkLabelAssociation): - """ Represents a ResponsiveAd label. - - Defines an association record between a ResponsiveAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see ResponsiveAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkResponsiveAdLabel, self).__init__(label_association, status) - -class BulkResponsiveSearchAdLabel(_BulkLabelAssociation): - """ Represents a ResponsiveSearchAd label. - - Defines an association record between a ResponsiveSearchAd and a Label that can be uploaded and downloaded in a bulk file. - - For more information, see ResponsiveSearchAd Label at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, label_association=None, status=None): - super(BulkResponsiveSearchAdLabel, self).__init__(label_association, status) \ No newline at end of file diff --git a/bingads/v12/bulk/entities/target_criterions/__init__.py b/bingads/v12/bulk/entities/target_criterions/__init__.py deleted file mode 100644 index b11e590b..00000000 --- a/bingads/v12/bulk/entities/target_criterions/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .bulk_ad_group_age_criterion import * -from .bulk_ad_group_day_time_criterion import * -from .bulk_ad_group_device_criterion import * -from .bulk_ad_group_gender_criterion import * -from .bulk_ad_group_location_criterion import * -from .bulk_ad_group_location_intent_criterion import * -from .bulk_ad_group_negative_location_criterion import * -from .bulk_ad_group_radius_criterion import * -from .bulk_ad_group_profile_criterion import * -from .bulk_ad_group_negative_age_criterion import * -from .bulk_ad_group_negative_gender_criterion import * -from .bulk_ad_group_negative_profile_criterion import * -from .bulk_campaign_age_criterion import * -from .bulk_campaign_day_time_criterion import * -from .bulk_campaign_device_criterion import * -from .bulk_campaign_gender_criterion import * -from .bulk_campaign_location_criterion import * -from .bulk_campaign_location_intent_criterion import * -from .bulk_campaign_negative_location_criterion import * -from .bulk_campaign_radius_criterion import * -from .bulk_campaign_profile_criterion import * diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_age_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_age_criterion.py deleted file mode 100644 index f689bb55..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_age_criterion.py +++ /dev/null @@ -1,123 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupAgeCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Age Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Age Criterion record in a bulk file. - - For more information, see Ad Group Age Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupAgeCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_AgeTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_AgeTarget(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupAgeCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AgeCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'AgeCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupAgeCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupAgeCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_day_time_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_day_time_criterion.py deleted file mode 100644 index c045cde4..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_day_time_criterion.py +++ /dev/null @@ -1,143 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupDayTimeCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Day Time Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Day Time Criterion record in a bulk file. - - For more information, see Ad Group Day Time Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupDayTimeCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_DayTimeTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_DayTimeTarget(c.biddable_ad_group_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.FromHour, - field_to_csv=lambda c: field_to_csv_FromHour(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_FromHour(c.biddable_ad_group_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.FromMinute, - field_to_csv=lambda c: field_to_csv_FromMinute(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_FromMinute(c.biddable_ad_group_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.ToHour, - field_to_csv=lambda c: field_to_csv_ToHour(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_ToHour(c.biddable_ad_group_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ToMinute, - field_to_csv=lambda c: field_to_csv_ToMinute(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_ToMinute(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupDayTimeCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('DayTimeCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'DayTimeCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupDayTimeCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupDayTimeCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_device_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_device_criterion.py deleted file mode 100644 index aebf9c0a..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_device_criterion.py +++ /dev/null @@ -1,128 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupDeviceCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Device Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Device Criterion record in a bulk file. - - For more information, see Ad Group Device Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupDeviceCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_DeviceTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_DeviceTarget(c.biddable_ad_group_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.OsNames, - field_to_csv=lambda c: field_to_csv_OSName(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_OSName(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupDeviceCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('DeviceCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'DeviceCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupDeviceCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupDeviceCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_gender_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_gender_criterion.py deleted file mode 100644 index a799fc78..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_gender_criterion.py +++ /dev/null @@ -1,123 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupGenderCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Gender Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Gender Criterion record in a bulk file. - - For more information, see Ad Group Gender Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupGenderCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_GenderTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_GenderTarget(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupGenderCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('GenderCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'GenderCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupGenderCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupGenderCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_criterion.py deleted file mode 100644 index 9a2198c1..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_criterion.py +++ /dev/null @@ -1,133 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupLocationCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Location Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Location Criterion record in a bulk file. - - For more information, see Ad Group Location Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupLocationCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationTarget(c.biddable_ad_group_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.SubType, - field_to_csv=lambda c: field_to_csv_LocationType(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationType(c.biddable_ad_group_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_LocationName(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationName(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupLocationCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'LocationCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupLocationCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupLocationCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_intent_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_intent_criterion.py deleted file mode 100644 index 84825c4e..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_location_intent_criterion.py +++ /dev/null @@ -1,116 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupLocationIntentCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Location Intent Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Location Intent Criterion record in a bulk file. - - For more information, see Ad Group Age Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupLocationIntentCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationIntentTarget(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationIntentTarget(c.biddable_ad_group_criterion, v) - ), - ] - - @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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupLocationIntentCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationIntentCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'LocationIntentCriterion' - row_values.convert_to_entity(self, BulkAdGroupLocationIntentCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupLocationIntentCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_age_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_age_criterion.py deleted file mode 100644 index 3a239cc1..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_age_criterion.py +++ /dev/null @@ -1,116 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupNegativeAgeCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Negative Age Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Age Criterion record in a bulk file. - - For more information, see Ad Group Negative Age Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeAgeCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_AgeTarget(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_AgeTarget(c.negative_ad_group_criterion, v) - ), - ] - - @property - def negative_ad_group_criterion(self): - """ Defines a Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeAgeCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AgeCriterion') - self._negative_ad_group_criterion.Criterion.Type = 'AgeCriterion' - row_values.convert_to_entity(self, BulkAdGroupNegativeAgeCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeAgeCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_gender_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_gender_criterion.py deleted file mode 100644 index 7b91d220..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_gender_criterion.py +++ /dev/null @@ -1,116 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupNegativeGenderCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Negative Gender Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Gender Criterion record in a bulk file. - - For more information, see Ad Group Negative Gender Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManGenderr` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeGenderCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_GenderTarget(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_GenderTarget(c.negative_ad_group_criterion, v) - ), - ] - - @property - def negative_ad_group_criterion(self): - """ Defines a Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeGenderCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('GenderCriterion') - self._negative_ad_group_criterion.Criterion.Type = 'GenderCriterion' - row_values.convert_to_entity(self, BulkAdGroupNegativeGenderCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeGenderCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_location_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_location_criterion.py deleted file mode 100644 index 1fce3a9b..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_location_criterion.py +++ /dev/null @@ -1,126 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupNegativeLocationCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Negative Location Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Location Criterion record in a bulk file. - - For more information, see Ad Group Negative Location Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeLocationCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationTarget(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationTarget(c.negative_ad_group_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.SubType, - field_to_csv=lambda c: field_to_csv_LocationType(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationType(c.negative_ad_group_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_LocationName(c.negative_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationName(c.negative_ad_group_criterion, v) - ), - ] - - @property - def negative_ad_group_criterion(self): - """ Defines a Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeLocationCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationCriterion') - self._negative_ad_group_criterion.Criterion.Type = 'LocationCriterion' - row_values.convert_to_entity(self, BulkAdGroupNegativeLocationCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeLocationCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_profile_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_profile_criterion.py deleted file mode 100644 index daef88b4..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_negative_profile_criterion.py +++ /dev/null @@ -1,217 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * -from abc import ABCMeta, abstractmethod - - -class BulkAdGroupNegativeProfileCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Negative Profile Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Profile Criterion record in a bulk file. - - For more information, see Ad Group Negative Profile Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManProfiler` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeProfileCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.Profile, - field_to_csv=lambda c: c.profile_name, - csv_to_field=lambda c, v: setattr(c, 'profile_name', v) - ), - _SimpleBulkMapping( - _StringTable.ProfileId, - field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Criterion.ProfileId), - csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion.Criterion, 'ProfileId', int(v) if v else None) - ), - ] - - @property - def negative_ad_group_criterion(self): - """ Defines a Ad Group Criterion """ - - return self._negative_ad_group_criterion - - @negative_ad_group_criterion.setter - def negative_ad_group_criterion(self, negative_ad_group_criterion): - self._negative_ad_group_criterion = negative_ad_group_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_ad_group_criterion, 'negative_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupNegativeProfileCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion') - self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion' - self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProfileCriterion') - self._negative_ad_group_criterion.Criterion.Type = 'ProfileCriterion' - self._negative_ad_group_criterion.Criterion.ProfileType = self.profile_type() - row_values.convert_to_entity(self, BulkAdGroupNegativeProfileCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupNegativeProfileCriterion, self).read_additional_data(stream_reader) - - @abstractmethod - def profile_type(self): - pass - -class BulkAdGroupNegativeCompanyNameCriterion(BulkAdGroupNegativeProfileCriterion): - """ Represents an Ad Group Negative CompanyName Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative CompanyName Criterion record in a bulk file. - - For more information, see Ad Group Negative CompanyName Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManCompanyNamer` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeCompanyNameCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - def profile_type(self): - return 'CompanyName' - - -class BulkAdGroupNegativeIndustryCriterion(BulkAdGroupNegativeProfileCriterion): - """ Represents an Ad Group Negative Industry Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative Industry Criterion record in a bulk file. - - For more information, see Ad Group Negative Industry Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManIndustryr` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeIndustryCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - def profile_type(self): - return 'Industry' - - -class BulkAdGroupNegativeJobFunctionCriterion(BulkAdGroupNegativeProfileCriterion): - """ Represents an Ad Group Negative JobFunction Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the - Ad Group Negative JobFunction Criterion record in a bulk file. - - For more information, see Ad Group Negative JobFunction Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManJobFunctionr` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupNegativeJobFunctionCriterion, self).__init__() - - self._negative_ad_group_criterion = negative_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name = ad_group_name - - def profile_type(self): - return 'JobFunction' \ No newline at end of file diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_profile_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_profile_criterion.py deleted file mode 100644 index ddb17587..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_profile_criterion.py +++ /dev/null @@ -1,222 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * -from abc import ABCMeta, abstractmethod - -class BulkAdGroupProfileCriterion(_SingleRecordBulkEntity): - """ The base class for Ad Group level profile criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written in a bulk file. - - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupProfileCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Profile, - field_to_csv=lambda c: c.profile_name, - csv_to_field=lambda c, v: setattr(c, 'profile_name', v) - ), - _SimpleBulkMapping( - _StringTable.ProfileId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Criterion.ProfileId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion.Criterion, 'ProfileId', int(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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - @abstractmethod - def profile_type(self): - pass - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupProfileCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProfileCriterion') - self._biddable_ad_group_criterion.Criterion.ProfileType = self.profile_type() - self._biddable_ad_group_criterion.Criterion.Type = 'ProfileCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupProfileCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupProfileCriterion, self).read_additional_data(stream_reader) - - -class BulkAdGroupCompanyNameCriterion(BulkAdGroupProfileCriterion): - """ Represents an Ad Group CompanyName Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group CompanyName Criterion record in a bulk file. - - For more information, see Ad Group CompanyName Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupCompanyNameCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - def profile_type(self): - return 'CompanyName' - - -class BulkAdGroupIndustryCriterion(BulkAdGroupProfileCriterion): - """ Represents an Ad Group Industry Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Industry Criterion record in a bulk file. - - For more information, see Ad Group Industry Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupIndustryCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - def profile_type(self): - return 'Industry' - - -class BulkAdGroupJobFunctionCriterion(BulkAdGroupProfileCriterion): - """ Represents an Ad Group JobFunction Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group JobFunction Criterion record in a bulk file. - - For more information, see Ad Group JobFunction Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupJobFunctionCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - def profile_type(self): - return 'JobFunction' \ No newline at end of file diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_radius_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_radius_criterion.py deleted file mode 100644 index d9307c9a..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_ad_group_radius_criterion.py +++ /dev/null @@ -1,143 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkAdGroupRadiusCriterion(_SingleRecordBulkEntity): - """ Represents an Ad Group Radius Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the - Ad Group Radius Criterion record in a bulk file. - - For more information, see Ad Group Radius Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_ad_group_criterion=None, - campaign_name=None, - ad_group_name=None, ): - super(BulkAdGroupRadiusCriterion, self).__init__() - - self._biddable_ad_group_criterion = biddable_ad_group_criterion - self._campaign_name = campaign_name - self._ad_group_name =ad_group_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.AdGroupId), - csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion, 'AdGroupId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.AdGroup, - field_to_csv=lambda c: c.ad_group_name, - csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_ad_group_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_RadiusName(c.biddable_ad_group_criterion), - csv_to_field=lambda c, v: csv_to_field_RadiusName(c.biddable_ad_group_criterion, v) - ), - _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 - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - @property - def ad_group_name(self): - """ The name of the Ad Group - - :rtype: str - """ - - return self._ad_group_name - - @ad_group_name.setter - def ad_group_name(self, ad_group_name): - self._ad_group_name = ad_group_name - - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_ad_group_criterion, 'biddable_ad_group_criterion') - self.convert_to_values(row_values, BulkAdGroupRadiusCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion') - self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion' - self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('RadiusCriterion') - self._biddable_ad_group_criterion.Criterion.Type = 'RadiusCriterion' - self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkAdGroupRadiusCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkAdGroupRadiusCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_age_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_age_criterion.py deleted file mode 100644 index 96d099c5..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_age_criterion.py +++ /dev/null @@ -1,102 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignAgeCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Age Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Age Criterion record in a bulk file. - - For more information, see Campaign Age Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignAgeCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_AgeTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_AgeTarget(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignAgeCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('AgeCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'AgeCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignAgeCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignAgeCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_day_time_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_day_time_criterion.py deleted file mode 100644 index 13b864e0..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_day_time_criterion.py +++ /dev/null @@ -1,122 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignDayTimeCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Day Time Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Day Time Criterion record in a bulk file. - - For more information, see Campaign Day Time Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignDayTimeCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_DayTimeTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_DayTimeTarget(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.FromHour, - field_to_csv=lambda c: field_to_csv_FromHour(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_FromHour(c.biddable_campaign_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.FromMinute, - field_to_csv=lambda c: field_to_csv_FromMinute(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_FromMinute(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.ToHour, - field_to_csv=lambda c: field_to_csv_ToHour(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_ToHour(c.biddable_campaign_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ToMinute, - field_to_csv=lambda c: field_to_csv_ToMinute(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_ToMinute(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignDayTimeCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('DayTimeCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'DayTimeCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignDayTimeCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignDayTimeCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_device_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_device_criterion.py deleted file mode 100644 index 7825c705..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_device_criterion.py +++ /dev/null @@ -1,107 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignDeviceCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Device Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Device Criterion record in a bulk file. - - For more information, see Campaign Device Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignDeviceCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_DeviceTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_DeviceTarget(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.OsNames, - field_to_csv=lambda c: field_to_csv_OSName(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_OSName(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignDeviceCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('DeviceCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'DeviceCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignDeviceCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignDeviceCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_gender_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_gender_criterion.py deleted file mode 100644 index d47a92fe..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_gender_criterion.py +++ /dev/null @@ -1,102 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignGenderCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Gender Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Gender Criterion record in a bulk file. - - For more information, see Campaign Gender Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignGenderCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_GenderTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_GenderTarget(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignGenderCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('GenderCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'GenderCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignGenderCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignGenderCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_criterion.py deleted file mode 100644 index 0fdf4348..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_criterion.py +++ /dev/null @@ -1,112 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignLocationCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Location Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Location Criterion record in a bulk file. - - For more information, see Campaign Location Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignLocationCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationTarget(c.biddable_campaign_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.SubType, - field_to_csv=lambda c: field_to_csv_LocationType(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationType(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_LocationName(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationName(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignLocationCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'LocationCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignLocationCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignLocationCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_intent_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_intent_criterion.py deleted file mode 100644 index 29969176..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_location_intent_criterion.py +++ /dev/null @@ -1,95 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignLocationIntentCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Location Intent Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Location Intent Criterion record in a bulk file. - - For more information, see Campaign Location Intent Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignLocationIntentCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationIntentTarget(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationIntentTarget(c.biddable_campaign_criterion, v) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignLocationIntentCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationIntentCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'LocationIntentCriterion' - row_values.convert_to_entity(self, BulkCampaignLocationIntentCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignLocationIntentCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_negative_location_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_negative_location_criterion.py deleted file mode 100644 index 52b2368f..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_negative_location_criterion.py +++ /dev/null @@ -1,105 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignNegativeLocationCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Negative Location Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`negative_campaign_criterion` property that can be read and written as fields of the - Campaign Negative Location Criterion record in a bulk file. - - For more information, see Campaign Negative Location Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - negative_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignNegativeLocationCriterion, self).__init__() - - self._negative_campaign_criterion = negative_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.Target, - field_to_csv=lambda c: field_to_csv_LocationTarget(c.negative_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationTarget(c.negative_campaign_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.SubType, - field_to_csv=lambda c: field_to_csv_LocationType(c.negative_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationType(c.negative_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_LocationName(c.negative_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LocationName(c.negative_campaign_criterion, v) - ), - ] - - @property - def negative_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._negative_campaign_criterion - - @negative_campaign_criterion.setter - def negative_campaign_criterion(self, negative_campaign_criterion): - self._negative_campaign_criterion = negative_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.negative_campaign_criterion, 'negative_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignNegativeLocationCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._negative_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeCampaignCriterion') - self._negative_campaign_criterion.Type = 'NegativeCampaignCriterion' - self._negative_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('LocationCriterion') - self._negative_campaign_criterion.Criterion.Type = 'LocationCriterion' - row_values.convert_to_entity(self, BulkCampaignNegativeLocationCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignNegativeLocationCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_profile_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_profile_criterion.py deleted file mode 100644 index 7cfd8ef6..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_profile_criterion.py +++ /dev/null @@ -1,193 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * -from abc import ABCMeta, abstractmethod - -class BulkCampaignProfileCriterion(_SingleRecordBulkEntity): - """ The base class for campaign level profile criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written in a bulk file. - - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignProfileCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Profile, - field_to_csv=lambda c: c.profile_name, - csv_to_field=lambda c, v: setattr(c, 'profile_name', v) - ), - _SimpleBulkMapping( - _StringTable.ProfileId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Criterion.ProfileId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion.Criterion, 'ProfileId', int(v) if v else None) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignProfileCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProfileCriterion') - self._biddable_campaign_criterion.Criterion.ProfileType = self.profile_type() - self._biddable_campaign_criterion.Criterion.Type = 'ProfileCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignProfileCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignProfileCriterion, self).read_additional_data(stream_reader) - - @abstractmethod - def profile_type(self): - pass - -class BulkCampaignCompanyNameCriterion(BulkCampaignProfileCriterion): - """ Represents an Campaign CompanyName Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign CompanyName Criterion record in a bulk file. - - For more information, see Campaign CompanyName Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None): - super(BulkCampaignCompanyNameCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - def profile_type(self): - return 'CompanyName' - -class BulkCampaignIndustryCriterion(BulkCampaignProfileCriterion): - """ Represents an Campaign Industry Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Industry Criterion record in a bulk file. - - For more information, see Campaign Industry Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None): - super(BulkCampaignIndustryCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - def profile_type(self): - return 'Industry' - -class BulkCampaignJobFunctionCriterion(BulkCampaignProfileCriterion): - """ Represents an Campaign JobFunction Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign JobFunction Criterion record in a bulk file. - - For more information, see Campaign JobFunction Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None): - super(BulkCampaignJobFunctionCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - def profile_type(self): - return 'JobFunction' \ No newline at end of file diff --git a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_radius_criterion.py b/bingads/v12/bulk/entities/target_criterions/bulk_campaign_radius_criterion.py deleted file mode 100644 index b0058a44..00000000 --- a/bingads/v12/bulk/entities/target_criterions/bulk_campaign_radius_criterion.py +++ /dev/null @@ -1,122 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12 -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.extensions import * - -class BulkCampaignRadiusCriterion(_SingleRecordBulkEntity): - """ Represents an Campaign Radius Criterion that can be read or written in a bulk file. - - This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written as fields of the - Campaign Radius Criterion record in a bulk file. - - For more information, see Campaign Radius Criterion at https://go.microsoft.com/fwlink/?linkid=846127. - - *See also:* - - * :class:`.BulkServiceManager` - * :class:`.BulkOperation` - * :class:`.BulkFileReader` - * :class:`.BulkFileWriter` - """ - - def __init__(self, - biddable_campaign_criterion=None, - campaign_name=None, ): - super(BulkCampaignRadiusCriterion, self).__init__() - - self._biddable_campaign_criterion = biddable_campaign_criterion - self._campaign_name = campaign_name - - _MAPPINGS = [ - _SimpleBulkMapping( - _StringTable.Status, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Status), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Status', v if v else None) - ), - _SimpleBulkMapping( - _StringTable.Id, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'Id', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.ParentId, - field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.CampaignId), - csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion, 'CampaignId', int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Campaign, - field_to_csv=lambda c: c.campaign_name, - csv_to_field=lambda c, v: setattr(c, 'campaign_name', v) - ), - _SimpleBulkMapping( - _StringTable.BidAdjustment, - field_to_csv=lambda c: field_to_csv_BidAdjustment(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_BidAdjustment(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Name, - field_to_csv=lambda c: field_to_csv_RadiusName(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_RadiusName(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Radius, - field_to_csv=lambda c: field_to_csv_Radius(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_Radius(c.biddable_campaign_criterion, int(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Unit, - field_to_csv=lambda c: field_to_csv_RadiusUnit(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_RadiusUnit(c.biddable_campaign_criterion, v) - ), - _SimpleBulkMapping( - _StringTable.Latitude, - field_to_csv=lambda c: field_to_csv_LatitudeDegrees(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LatitudeDegrees(c.biddable_campaign_criterion, float(v) if v else None) - ), - _SimpleBulkMapping( - _StringTable.Longitude, - field_to_csv=lambda c: field_to_csv_LongitudeDegrees(c.biddable_campaign_criterion), - csv_to_field=lambda c, v: csv_to_field_LongitudeDegrees(c.biddable_campaign_criterion, float(v) if v else None) - ), - ] - - @property - def biddable_campaign_criterion(self): - """ Defines a Campaign Criterion """ - - return self._biddable_campaign_criterion - - @biddable_campaign_criterion.setter - def biddable_campaign_criterion(self, biddable_campaign_criterion): - self._biddable_campaign_criterion = biddable_campaign_criterion - - @property - def campaign_name(self): - """ The name of the Campaign - - :rtype: str - """ - - return self._campaign_name - - @campaign_name.setter - def campaign_name(self, campaign_name): - self._campaign_name = campaign_name - - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - self._validate_property_not_null(self.biddable_campaign_criterion, 'biddable_campaign_criterion') - self.convert_to_values(row_values, BulkCampaignRadiusCriterion._MAPPINGS) - - def process_mappings_from_row_values(self, row_values): - self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableCampaignCriterion') - self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion' - self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('RadiusCriterion') - self._biddable_campaign_criterion.Criterion.Type = 'RadiusCriterion' - self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create('BidMultiplier') - self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier' - row_values.convert_to_entity(self, BulkCampaignRadiusCriterion._MAPPINGS) - - def read_additional_data(self, stream_reader): - super(BulkCampaignRadiusCriterion, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/entities/unknown_bulk_entity.py b/bingads/v12/bulk/entities/unknown_bulk_entity.py deleted file mode 100644 index c8b4ddff..00000000 --- a/bingads/v12/bulk/entities/unknown_bulk_entity.py +++ /dev/null @@ -1,28 +0,0 @@ -from bingads.v12.internal.bulk.entities.single_record_bulk_entity import _SingleRecordBulkEntity - - -class UnknownBulkEntity(_SingleRecordBulkEntity): - """ Reserved to support new record types that may be added to the Bulk schema. """ - - def __init__(self): - super(UnknownBulkEntity, self).__init__() - self._values = None - - @property - def values(self): - """ The forward compatibility map of fields and values. - - :rtype: dict | None - """ - - return self._values - - def process_mappings_from_row_values(self, row_values): - self._values = row_values.to_dict() - - def process_mappings_to_row_values(self, row_values): - for (key, value) in self._values.items(): - row_values[key] = value - - def read_additional_data(self, stream_reader): - super(UnknownBulkEntity, self).read_additional_data(stream_reader) diff --git a/bingads/v12/bulk/enums.py b/bingads/v12/bulk/enums.py deleted file mode 100644 index 160b98c1..00000000 --- a/bingads/v12/bulk/enums.py +++ /dev/null @@ -1,13 +0,0 @@ -from enum import Enum - -class ResultFileType(Enum): - """ Defines the possible types of result files. """ - - full_download = 1 - """ The result file represents the full sync of entities that were specified in the download request. """ - - partial_download = 2 - """ The result file represents the partial sync of entities that were specified in the download request. """ - - upload = 3 - """ The result file represents the entities specified in the upload request, or the corresponding errors, or both entities and errors. """ diff --git a/bingads/v12/bulk/exceptions.py b/bingads/v12/bulk/exceptions.py deleted file mode 100644 index 291af0a7..00000000 --- a/bingads/v12/bulk/exceptions.py +++ /dev/null @@ -1,115 +0,0 @@ -from bingads.exceptions import SdkException - - -class BulkException(SdkException): - def __init__(self, message, errors): - super(BulkException, self).__init__(message) - self._errors = errors - - @property - def errors(self): - """ The list of operation errors returned by the bulk service. - - :rtype: list[OperationError] - """ - return self._errors - - -class BulkUploadException(SdkException): - def __init__(self, message): - super(BulkUploadException, self).__init__(message) - - -class BulkDownloadException(SdkException): - def __init__(self, message): - super(BulkDownloadException, self).__init__(message) - - -class EntityReadException(SdkException): - def __init__(self, message, row_values=None, inner_exception=None): - super(EntityReadException, self).__init__(message) - self._row_values = row_values - self._inner_exception = inner_exception - - @property - def row_values(self): - return self._row_values - - @property - def inner_exception(self): - return self._inner_exception - - -class EntityWriteException(SdkException): - def __init__(self, message, inner_exception=None): - super(EntityWriteException, self).__init__(message) - self._inner_exception = inner_exception - - @property - def inner_exception(self): - return self._inner_exception - - -class OperationError: - """ Defines an error object that contains the details that explain why the service operation failed. """ - - def __init__(self, - code=None, - details=None, - error_code=None, - message=None,): - self._code = code - self._details = details - self._error_code = error_code - self._message = message - - @property - def code(self): - """ A numeric error code that identifies the error - - :rtype: int - """ - - return self._code - - @code.setter - def code(self, value): - self._code = value - - @property - def details(self): - """ A message that provides additional details about the error. This string can be empty. - - :rtype: str - """ - - return self._details - - @details.setter - def details(self, value): - self._details = value - - @property - def error_code(self): - """ A symbolic string constant that identifies the error. For example, UserIsNotAuthorized. - - :rtype: str - """ - - return self._error_code - - @error_code.setter - def error_code(self, value): - self._error_code = value - - @property - def message(self): - """ A message that describes the error. - - :rtype: str - """ - return self._message - - @message.setter - def message(self, value): - self._message = value diff --git a/bingads/v12/bulk/file_reader.py b/bingads/v12/bulk/file_reader.py deleted file mode 100644 index d2b355d9..00000000 --- a/bingads/v12/bulk/file_reader.py +++ /dev/null @@ -1,157 +0,0 @@ -from .enums import ResultFileType -from .entities.bulk_entity import BulkEntity -from bingads.v12.internal.bulk.stream_reader import _BulkStreamReader -from bingads.v12.internal.bulk.entities.multi_record_bulk_entity import _MultiRecordBulkEntity - - -class BulkFileReader: - """ Provides a method to read bulk entities from a bulk file and make them accessible as an enumerable list. - - For more information about the Bulk File Schema, see https://go.microsoft.com/fwlink/?linkid=846127. - """ - - def __init__(self, - file_path, - file_type='Csv', - result_file_type=ResultFileType.full_download, - encoding='utf-8-sig'): - """ Initializes a new instance of this class with the specified file details. - - :param file_path: The path of the bulk file to read. - :type file_path: str - :param file_type: The bulk file type. - :type file_type: str - :param result_file_type: The result file type. - :type result_file_type: ResultFileType - :param encoding: The encoding of bulk file. - :type encoding: str - """ - - self._file_path = file_path - self._file_type = file_type - self._result_file_type = result_file_type - self._encoding = encoding - - self._is_for_full_download = result_file_type is ResultFileType.full_download - self._entities_iterator = None - self._bulk_stream_reader = _BulkStreamReader(file_path=self.file_path, file_type=self.file_type, encoding=self._encoding) - self._bulk_stream_reader.__enter__() - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._entities_iterator = None - self._bulk_stream_reader.__exit__(exc_type, exc_value, traceback) - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def close(self): - self.__exit__(None, None, None) - - def next(self): - return self.read_next_entity() - - def read_next_entity(self): - """ Reads next entity from the bulk file. - - :return: next entity - :rtype: BulkEntity - """ - - if self._entities_iterator is None: - self._entities_iterator = self.read_entities() - - return next(self._entities_iterator) - - def read_entities(self): - """ Gets an enumerable list of bulk entities that were read from the file. - - :return: an generator over the entities - :rtype: collections.Iterator[BulkEntity] - """ - - next_batch = self._read_next_batch() - - while next_batch is not None: - for entity in next_batch: - yield entity - next_batch = self._read_next_batch() - - def _read_next_batch(self): - """ Reads next batch of entities from the file. - - Batch means a set of related entities. - It can be one :class:`._SingleRecordBulkEntity`, one :class:`._MultiRecordBulkEntity` containing its child - entities or a set of related child entities (for example several :class:`.BulkSiteLink`s logically belonging - to the same SiteLink Ad Extension. - - :return: Next batch of entities - :rtype: _SingleRecordBulkEntity or _MultiRecordBulkEntity - """ - - next_object = self._bulk_stream_reader.read() - - if next_object is None: - return None - if next_object.can_enclose_in_multiline_entity: - multi_record_entity = next_object.enclose_in_multiline_entity() - multi_record_entity.read_related_data_from_stream(self._bulk_stream_reader) - if self._is_for_full_download: - return [multi_record_entity] - return self._extract_child_entities_if_needed(multi_record_entity) - if isinstance(next_object, BulkEntity): - return [next_object] - raise NotImplementedError() - - def _extract_child_entities_if_needed(self, entity): - # If the entity is a MultiLine entity and it has all child objects (delete all row was present), just return it - if not isinstance(entity, _MultiRecordBulkEntity) or entity.all_children_are_present: - yield entity - else: - # If not all child objects are present (there was no delete all row and we only have part of the MultiLine entity), return child object individually - for child_generator in ( - self._extract_child_entities_if_needed(child_entity) - for child_entity in entity.child_entities): - for child in child_generator: - yield child - - @property - def file_path(self): - """ The path of the bulk file to read. - - :rtype: str - """ - - return self._file_path - - @property - def file_type(self): - """ The bulk file type. - - :rtype: str - """ - - return self._file_type - - @property - def result_file_type(self): - """ The result file type. - - :rtype: ResultFileType - """ - - return self._result_file_type - - @property - def encoding(self): - """ The encoding of bulk file. - - :rtype: str - """ - - return self._encoding diff --git a/bingads/v12/bulk/file_writer.py b/bingads/v12/bulk/file_writer.py deleted file mode 100644 index f9a235c9..00000000 --- a/bingads/v12/bulk/file_writer.py +++ /dev/null @@ -1,63 +0,0 @@ -from bingads.v12.internal.bulk.object_writer import _BulkObjectWriter - - -class BulkFileWriter: - """ Provides methods to write bulk entities to a file. - - For more information about the Bulk File Schema, see https://go.microsoft.com/fwlink/?linkid=846127. - - :param file_path: The file path of the bulk file to write. - :type file_path: str - :param file_type: The bulk file type. - :type file_type: str - """ - - def __init__(self, file_path, file_type='Csv'): - self._file_path = file_path - self._file_type = file_type - self._bulk_object_writer = _BulkObjectWriter(file_path=self.file_path, file_type=self.file_type) - self._bulk_object_writer.__enter__() - self._bulk_object_writer.write_file_metadata() - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._bulk_object_writer.__exit__(exc_type, exc_value, traceback) - - def close(self): - self.__exit__(None, None, None) - - def write_entity(self, entity, exclude_readonly_data=False): - """ Writes the specified :class:`.BulkEntity` to the file. - - Bulk entities that are derived from :class:`._SingleRecordBulkEntity` will be written to a single row in the file. - Bulk entities that are derived from :class:`._MultiRecordBulkEntity` will be written to multiple rows in the file. - - :param entity: The bulk entity to write to the file. - :type entity: BulkEntity - :param exclude_readonly_data: excludeReadonlyData indicates whether readonly data (such as errors, performance data etc.) - should be excluded when writing to file - :type exclude_readonly_data: bool - :rtype: None - """ - - entity.write_to_stream(self._bulk_object_writer, exclude_readonly_data=exclude_readonly_data) - - @property - def file_path(self): - """ The file path of the bulk file to write. - - :rtype: str - """ - - return self._file_path - - @property - def file_type(self): - """ The bulk file type. - - :rtype: str - """ - - return self._file_type diff --git a/bingads/v12/bulk/upload_parameters.py b/bingads/v12/bulk/upload_parameters.py deleted file mode 100644 index cdc0d7ca..00000000 --- a/bingads/v12/bulk/upload_parameters.py +++ /dev/null @@ -1,342 +0,0 @@ -from os import path - - -class FileUploadParameters: - """ Describes the available parameters when submitting a file for upload, such as the path of the upload result file. """ - - def __init__(self, - upload_file_path, - result_file_directory=None, - result_file_name=None, - overwrite_result_file=False, - compress_upload_file=True, - response_mode='ErrorsAndResults', - timeout_in_milliseconds=None, - rename_upload_file_to_match_request_id = True): - """ Initialize a new instance of this class. - - :param result_file_directory: The directory where the file will be downloaded. - :type result_file_directory: str - :param result_file_name: The name of the download result file. - :type result_file_name: str - :param overwrite_result_file: (optional) Whether the local result file should be overwritten if it already exists, default is False. - :type overwrite_result_file: bool - :param upload_file_path: The fully qualified local path of the upload file. - :type upload_file_path: str - :param compress_upload_file: (optional) Determines whether the upload file should be compressed before uploading. The default value is True. - :type compress_upload_file: bool - :param response_mode: (optional) Determines whether the bulk service should return upload errors with the corresponding entity data. - If not specified, this property is set by default to ErrorsAndResults. - :type response_mode: str - :param timeout_in_milliseconds: (optional) timeout for bulk upload operations in milliseconds - :type timeout_in_milliseconds: int - """ - - self._result_file_directory = result_file_directory - self._result_file_name = result_file_name - self._decompress_result_file = True - if result_file_name is not None: - _, ext = path.splitext(result_file_name) - if ext == '.zip': - self._decompress_result_file = False - self._overwrite_result_file = overwrite_result_file - self._submit_upload_parameters = SubmitUploadParameters( - upload_file_path=upload_file_path, - compress_upload_file=compress_upload_file, - response_mode=response_mode, - rename_upload_file_to_match_request_id= rename_upload_file_to_match_request_id - ) - self._timeout_in_milliseconds=timeout_in_milliseconds - - @property - def decompress_result_file(self): - return self._decompress_result_file - - @property - def upload_file_path(self): - """ The fully qualified local path of the upload file. - - :rtype: str - """ - - return self._submit_upload_parameters.upload_file_path - - @upload_file_path.setter - def upload_file_path(self, upload_file_path): - self._submit_upload_parameters.upload_file_path = upload_file_path - - @property - def compress_upload_file(self): - """ Determines whether the upload file should be compressed before uploading. The default value is True. - - :rtype: bool - """ - - return self._submit_upload_parameters.compress_upload_file - - @compress_upload_file.setter - def compress_upload_file(self, compress): - self._submit_upload_parameters.compress_upload_file = compress - - @property - def response_mode(self): - """ Determines whether the bulk service should return upload errors with the corresponding entity data. - - If not specified, this property is set by default to ErrorsAndResults. - - :rtype: str - """ - - return self._submit_upload_parameters.response_mode - - @response_mode.setter - def response_mode(self, value): - self._submit_upload_parameters.response_mode = value - - @property - def result_file_directory(self): - """ The directory where the file will be downloaded. - - :rtype: str - """ - - return self._result_file_directory - - @result_file_directory.setter - def result_file_directory(self, result_file_directory): - self._result_file_directory = result_file_directory - - @property - def result_file_name(self): - """ The name of the download result file. - - :rtype: str - """ - - return self._result_file_name - - @result_file_name.setter - def result_file_name(self, result_file_name): - self._result_file_name = result_file_name - - @property - def overwrite_result_file(self): - """ Whether the local result file should be overwritten if it already exists. - - :rtype: bool - """ - - return self._overwrite_result_file - - @overwrite_result_file.setter - def overwrite_result_file(self, overwrite): - self._overwrite_result_file = overwrite - - @property - def timeout_in_milliseconds(self): - return self._timeout_in_milliseconds - - -class SubmitUploadParameters(object): - """ Describes the minimum available parameters when submitting a file for upload, such as the path of the upload file. """ - - def __init__(self, - upload_file_path, - compress_upload_file=True, - response_mode='ErrorsAndResults', - timeout_in_milliseconds=None, - rename_upload_file_to_match_request_id=True): - """ Initialize a new instance of this class. - - :param upload_file_path: The fully qualified local path of the upload file. - :type upload_file_path: str - :param compress_upload_file: (optional) Determines whether the upload file should be compressed before uploading. The default value is True. - :type compress_upload_file: bool - :param response_mode: (optional) Determines whether the bulk service should return upload errors with the corresponding entity data. - If not specified, this property is set by default to ErrorsAndResults. - :type response_mode: str - :param timeout_in_milliseconds: (optional) timeout for submit upload operations in milliseconds - :type timeout_in_milliseconds: int - """ - - self._upload_file_path = upload_file_path - self._compress_upload_file = compress_upload_file - self._response_mode = response_mode - self._timeout_in_milliseconds = timeout_in_milliseconds - self._rename_upload_file_to_match_request_id=rename_upload_file_to_match_request_id - - @property - def rename_upload_file_to_match_request_id(self): - """ rename the upload file to request id or not. - - :rtype: boolean - """ - return self._rename_upload_file_to_match_request_id; - - @property - def upload_file_path(self): - """ The fully qualified local path of the upload file. - - :rtype: str - """ - - return self._upload_file_path - - @property - def compress_upload_file(self): - """ Determines whether the upload file should be compressed before uploading. The default value is True. - - :rtype: bool - """ - - return self._compress_upload_file - - @upload_file_path.setter - def upload_file_path(self, upload_file_path): - self._upload_file_path = upload_file_path - - @compress_upload_file.setter - def compress_upload_file(self, compress): - self._compress_upload_file = compress - - @property - def response_mode(self): - """ Determines whether the bulk service should return upload errors with the corresponding entity data. - - If not specified, this property is set by default to ErrorsAndResults. - - :rtype: str - """ - - return self._response_mode - - @response_mode.setter - def response_mode(self, value): - self._response_mode = value - - @property - def timeout_in_milliseconds(self): - return self._timeout_in_milliseconds - - @timeout_in_milliseconds.setter - def timeout_in_milliseconds(self, value): - self._timeout_in_milliseconds = value - - -class EntityUploadParameters(object): - """ Describes the available parameters when submitting entities for upload, such as the entities that you want to upload. """ - - def __init__(self, - entities, - result_file_directory=None, - result_file_name=None, - overwrite_result_file=False, - response_mode='ErrorsAndResults', - timeout_in_milliseconds=None): - """ Initializes a new instance of this class. - - :param entities: The list of bulk entities that you want to upload. - :type entities: collections.Iterable[BulkEntity] - :param result_file_directory: (optional) The directory where the file will be downloaded. - :type result_file_directory: str - :param result_file_name: (optional) The name of the download result file. - :type result_file_name: str - :param overwrite_result_file: (optional) Whether the local result file should be overwritten if it already exists. - :type overwrite_result_file: bool - :param response_mode: (optional) Determines whether the bulk service should return upload errors with the corresponding entity data. - If not specified, this property is set by default to ErrorsAndResults. - :type response_mode: str - :param timeout_in_milliseconds: (optional) timeout for entity upload operations in milliseconds - :type timeout_in_milliseconds: int - """ - - self._result_file_directory = result_file_directory - self._result_file_name = result_file_name - self._decompress_result_file = True - if result_file_name is not None: - _, ext = path.splitext(result_file_name) - if ext == '.zip': - self._decompress_result_file = False - self._entities = entities - self._overwrite_result_file = overwrite_result_file - self._response_mode = response_mode - self._timeout_in_milliseconds = timeout_in_milliseconds - - @property - def decompress_result_file(self): - return self._decompress_result_file - - @property - def entities(self): - """ The list of bulk entities that you want to upload. - - :rtype: collections.Iterable[BulkEntity] - """ - - return self._entities - - @entities.setter - def entities(self, value): - self._entities = value - - @property - def response_mode(self): - """ Determines whether the bulk service should return upload errors with the corresponding entity data. - - If not specified, this property is set by default to ErrorsAndResults. - - :rtype: str - """ - - return self._response_mode - - @response_mode.setter - def response_mode(self, value): - self._response_mode = value - - @property - def result_file_directory(self): - """ The directory where the file will be downloaded. - - :rtype: str - """ - - return self._result_file_directory - - @result_file_directory.setter - def result_file_directory(self, result_file_directory): - self._result_file_directory = result_file_directory - - @property - def result_file_name(self): - """ The name of the download result file. - - :rtype: str - """ - - return self._result_file_name - - @result_file_name.setter - def result_file_name(self, result_file_name): - self._result_file_name = result_file_name - - @property - def overwrite_result_file(self): - """ Whether the local result file should be overwritten if it already exists. - - :rtype: bool - """ - - return self._overwrite_result_file - - @overwrite_result_file.setter - def overwrite_result_file(self, overwrite): - self._overwrite_result_file = overwrite - - @property - def timeout_in_milliseconds(self): - return self._timeout_in_milliseconds - - @timeout_in_milliseconds.setter - def timeout_in_milliseconds(self, value): - self._timeout_in_milliseconds = value diff --git a/bingads/v12/internal/__init__.py b/bingads/v12/internal/__init__.py deleted file mode 100644 index 40e8cff3..00000000 --- a/bingads/v12/internal/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .extensions import * diff --git a/bingads/v12/internal/bulk/__init__.py b/bingads/v12/internal/bulk/__init__.py deleted file mode 100644 index c075ee1a..00000000 --- a/bingads/v12/internal/bulk/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' diff --git a/bingads/v12/internal/bulk/bulk_object.py b/bingads/v12/internal/bulk/bulk_object.py deleted file mode 100644 index 9f46bf2f..00000000 --- a/bingads/v12/internal/bulk/bulk_object.py +++ /dev/null @@ -1,119 +0,0 @@ -from abc import ABCMeta, abstractmethod, abstractproperty -from future.utils import with_metaclass - -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.bulk import EntityWriteException - - -class _BulkObject(with_metaclass(ABCMeta)): - """ The abstract base class for all bulk objects that can be read and written in a file that conforms to the Bing Ad Bulk File Schema. - - For more information about the Bulk File Schema, see https://go.microsoft.com/fwlink/?linkid=846127. - """ - - @abstractmethod - def read_from_row_values(self, row_values): - """ Read object data from a single row. - - *Example:* - - * SingleLineBulkEntity: reads entity fields. - * BulkError: reads error fields. - * BulkEntityIdentifier: reads identifier fields (Id, status etc.). - - :param row_values: - :type row_values: _RowValues - """ - - raise NotImplementedError() - - @abstractmethod - def write_to_row_values(self, row_values, exclude_readonly_data): - """ Writes object data to a single row. - - *Example:* - - * SingleLineBulkEntity: writes entity fields. - * BulkEntityIdentifier: writes identifier fields (Id, status etc.) - - :param row_values: - :type row_values: _RowValues - """ - - raise NotImplementedError() - - @abstractmethod - def read_related_data_from_stream(self, stream_reader): - """ Reads object data from consecutive rows. - - *Example:* - - * SingleLineBulkEntity: reads entity errors. - * MultilineBulkEntity: reads child entities. - - :param stream_reader: - :type stream_reader: _BulkStreamReader - """ - - pass - - @abstractmethod - def write_to_stream(self, row_writer, exclude_readonly_data): - """ Writes object data to consecutive rows. - - *Example:* - - * SingleLineBulkEntity: writes entity. - * MultilineBulkEntity: writes child entities. - * BulkEntityIdentifier: writes identifier information (Id, status etc.) - - :param row_writer: - :type row_writer: :class:`._BulkObjectWriter` - """ - - raise NotImplementedError() - - @abstractproperty - def can_enclose_in_multiline_entity(self): - """ Returns true if the entity is part of multiline entity, false otherwise. - - *Example:* - - * BulkSiteLinkAdExtension: returns true - * BulkCampaignTarget: returns true - * BulkAdGroup: returns false - * BulkKeyword: returns false - - :rtype: bool - """ - return False - - @abstractmethod - def enclose_in_multiline_entity(self): - """ Creates a multiline entity containing this entity - - *Example:* - - * BulkSiteLink: returns BulkSiteLinkAdExtension containing this BulkSiteLink - * BulkCampaignAgeTargetBid: return BulkCampaignTarget containing this BulkCampaignAgeTargetBid - - :return: the wrapping multi-line entity - :rtype: :class:`._MultiRecordBulkEntity` - """ - raise NotImplementedError() - - def convert_to_values(self, row_values, mappings): - for mapping in mappings: - try: - mapping.convert_to_csv(self, row_values) - except Exception as ex: - raise self._create_entity_write_error(mapping, ex) - - def _create_entity_write_error(self, mapping, ex): - entity_type = str(type(self)) - if isinstance(mapping, _SimpleBulkMapping): - message = "Couldn't write column {0} of {1} entity: {2}".format(mapping.header, entity_type, ex) - else: - message = "Couldn't write {0} entity: {1}".format(entity_type, ex) - message += " See InnerException for error details." - return EntityWriteException(message=message, inner_exception=ex) diff --git a/bingads/v12/internal/bulk/bulk_object_factory.py b/bingads/v12/internal/bulk/bulk_object_factory.py deleted file mode 100644 index 0b06a1af..00000000 --- a/bingads/v12/internal/bulk/bulk_object_factory.py +++ /dev/null @@ -1,187 +0,0 @@ -from bingads.v12.bulk.entities import * -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.entity_info import _EntityInfo -from bingads.v12.bulk.entities.bulk_negative_sites import _BulkAdGroupNegativeSitesIdentifier, \ - _BulkCampaignNegativeSitesIdentifier -from bingads.v12.internal.bulk.format_version import _FormatVersion - - -class _BulkObjectFactory(): - INDIVIDUAL_ENTITY_MAP = { - _StringTable.Account: _EntityInfo(lambda: BulkAccount()), - _StringTable.Budget: _EntityInfo(lambda: BulkBudget()), - _StringTable.Campaign: _EntityInfo(lambda: BulkCampaign()), - _StringTable.AdGroup: _EntityInfo(lambda: BulkAdGroup()), - _StringTable.Keyword: _EntityInfo(lambda: BulkKeyword()), - _StringTable.CallAdExtension: _EntityInfo(lambda: BulkCallAdExtension()), - _StringTable.CampaignCallAdExtension: _EntityInfo(lambda: BulkCampaignCallAdExtension()), - _StringTable.ImageAdExtension: _EntityInfo(lambda: BulkImageAdExtension()), - _StringTable.AccountImageAdExtension: _EntityInfo(lambda: BulkAccountImageAdExtension()), - _StringTable.CampaignImageAdExtension: _EntityInfo(lambda: BulkCampaignImageAdExtension()), - _StringTable.AdGroupImageAdExtension: _EntityInfo(lambda: BulkAdGroupImageAdExtension()), - _StringTable.CalloutAdExtension: _EntityInfo(lambda: BulkCalloutAdExtension()), - _StringTable.AccountCalloutAdExtension: _EntityInfo(lambda: BulkAccountCalloutAdExtension()), - _StringTable.CampaignCalloutAdExtension: _EntityInfo(lambda: BulkCampaignCalloutAdExtension()), - _StringTable.AdGroupCalloutAdExtension: _EntityInfo(lambda: BulkAdGroupCalloutAdExtension()), - _StringTable.ReviewAdExtension: _EntityInfo(lambda: BulkReviewAdExtension()), - _StringTable.AccountReviewAdExtension: _EntityInfo(lambda: BulkAccountReviewAdExtension()), - _StringTable.CampaignReviewAdExtension: _EntityInfo(lambda: BulkCampaignReviewAdExtension()), - _StringTable.AdGroupReviewAdExtension: _EntityInfo(lambda: BulkAdGroupReviewAdExtension()), - _StringTable.LocationAdExtension: _EntityInfo(lambda: BulkLocationAdExtension()), - _StringTable.AccountLocationAdExtension: _EntityInfo(lambda: BulkAccountLocationAdExtension()), - _StringTable.CampaignLocationAdExtension: _EntityInfo(lambda: BulkCampaignLocationAdExtension()), - _StringTable.AppAdExtension: _EntityInfo(lambda: BulkAppAdExtension()), - _StringTable.AccountAppAdExtension: _EntityInfo(lambda: BulkAccountAppAdExtension()), - _StringTable.CampaignAppAdExtension: _EntityInfo(lambda: BulkCampaignAppAdExtension()), - _StringTable.AdGroupAppAdExtension: _EntityInfo(lambda: BulkAdGroupAppAdExtension()), - _StringTable.StructuredSnippetAdExtension: _EntityInfo(lambda: BulkStructuredSnippetAdExtension()), - _StringTable.AccountStructuredSnippetAdExtension: _EntityInfo(lambda: BulkAccountStructuredSnippetAdExtension()), - _StringTable.CampaignStructuredSnippetAdExtension: _EntityInfo(lambda: BulkCampaignStructuredSnippetAdExtension()), - _StringTable.AdGroupStructuredSnippetAdExtension: _EntityInfo(lambda: BulkAdGroupStructuredSnippetAdExtension()), - _StringTable.SitelinkAdExtension: _EntityInfo(lambda: BulkSitelinkAdExtension()), - _StringTable.AccountSitelinkAdExtension: _EntityInfo(lambda: BulkAccountSitelinkAdExtension()), - _StringTable.CampaignSitelinkAdExtension: _EntityInfo(lambda: BulkCampaignSitelinkAdExtension()), - _StringTable.AdGroupSitelinkAdExtension: _EntityInfo(lambda: BulkAdGroupSitelinkAdExtension()), - _StringTable.PriceAdExtension: _EntityInfo(lambda: BulkPriceAdExtension()), - _StringTable.AccountPriceAdExtension: _EntityInfo(lambda: BulkAccountPriceAdExtension()), - _StringTable.CampaignPriceAdExtension: _EntityInfo(lambda: BulkCampaignPriceAdExtension()), - _StringTable.AdGroupPriceAdExtension: _EntityInfo(lambda: BulkAdGroupPriceAdExtension()), - _StringTable.ProductAd: _EntityInfo(lambda: BulkProductAd()), - _StringTable.TextAd: _EntityInfo(lambda: BulkTextAd()), - _StringTable.AppInstallAd: _EntityInfo(lambda: BulkAppInstallAd()), - _StringTable.ExpandedTextAd: _EntityInfo(lambda: BulkExpandedTextAd()), - _StringTable.DynamicSearchAd: _EntityInfo(lambda: BulkDynamicSearchAd()), - _StringTable.ResponsiveAd: _EntityInfo(lambda: BulkResponsiveAd()), - _StringTable.ResponsiveSearchAd: _EntityInfo(lambda: BulkResponsiveSearchAd()), - "Campaign Negative Site": _EntityInfo( - lambda: BulkCampaignNegativeSite(), - _StringTable.Website, - lambda: _BulkCampaignNegativeSitesIdentifier() - ), - "Ad Group Negative Site": _EntityInfo( - lambda: BulkAdGroupNegativeSite(), - _StringTable.Website, - lambda: _BulkAdGroupNegativeSitesIdentifier() - ), - - _StringTable.NegativeKeywordList: _EntityInfo(lambda: BulkNegativeKeywordList()), - _StringTable.ListNegativeKeyword: _EntityInfo(lambda: BulkSharedNegativeKeyword()), - _StringTable.CampaignNegativeKeywordList: _EntityInfo(lambda: BulkCampaignNegativeKeywordList()), - _StringTable.CampaignNegativeKeyword: _EntityInfo(lambda: BulkCampaignNegativeKeyword()), - _StringTable.AdGroupNegativeKeyword: _EntityInfo(lambda: BulkAdGroupNegativeKeyword()), - 'Campaign Product Scope': _EntityInfo(lambda : BulkCampaignProductScope()), - 'Ad Group Product Partition': _EntityInfo(lambda : BulkAdGroupProductPartition()), - _StringTable.RemarketingList: _EntityInfo(lambda : BulkRemarketingList()), - _StringTable.AdGroupRemarketingListAssociation: _EntityInfo(lambda : BulkAdGroupRemarketingListAssociation()), - _StringTable.AdGroupNegativeRemarketingListAssociation: _EntityInfo(lambda : BulkAdGroupNegativeRemarketingListAssociation()), - _StringTable.CampaignRemarketingListAssociation: _EntityInfo(lambda : BulkCampaignRemarketingListAssociation()), - _StringTable.CampaignNegativeRemarketingListAssociation: _EntityInfo(lambda : BulkCampaignNegativeRemarketingListAssociation()), - _StringTable.CustomAudience: _EntityInfo(lambda : BulkCustomAudience()), - _StringTable.AdGroupCustomAudienceAssociation: _EntityInfo(lambda : BulkAdGroupCustomAudienceAssociation()), - _StringTable.AdGroupNegativeCustomAudienceAssociation: _EntityInfo(lambda : BulkAdGroupNegativeCustomAudienceAssociation()), - _StringTable.CampaignCustomAudienceAssociation: _EntityInfo(lambda : BulkCampaignCustomAudienceAssociation()), - _StringTable.CampaignNegativeCustomAudienceAssociation: _EntityInfo(lambda : BulkCampaignNegativeCustomAudienceAssociation()), - _StringTable.InMarketAudience: _EntityInfo(lambda : BulkInMarketAudience()), - _StringTable.AdGroupInMarketAudienceAssociation: _EntityInfo(lambda : BulkAdGroupInMarketAudienceAssociation()), - _StringTable.AdGroupNegativeInMarketAudienceAssociation: _EntityInfo(lambda : BulkAdGroupNegativeInMarketAudienceAssociation()), - _StringTable.CampaignInMarketAudienceAssociation: _EntityInfo(lambda : BulkCampaignInMarketAudienceAssociation()), - _StringTable.CampaignNegativeInMarketAudienceAssociation: _EntityInfo(lambda : BulkCampaignNegativeInMarketAudienceAssociation()), - 'Campaign Negative Dynamic Search Ad Target': _EntityInfo(lambda: BulkCampaignNegativeDynamicSearchAdTarget()), - 'Ad Group Dynamic Search Ad Target': _EntityInfo(lambda: BulkAdGroupDynamicSearchAdTarget()), - 'Ad Group Negative Dynamic Search Ad Target': _EntityInfo(lambda: BulkAdGroupNegativeDynamicSearchAdTarget()), - 'Ad Group Age Criterion': _EntityInfo(lambda: BulkAdGroupAgeCriterion()), - 'Ad Group DayTime Criterion': _EntityInfo(lambda: BulkAdGroupDayTimeCriterion()), - 'Ad Group DeviceOS Criterion': _EntityInfo(lambda: BulkAdGroupDeviceCriterion()), - 'Ad Group Gender Criterion': _EntityInfo(lambda: BulkAdGroupGenderCriterion()), - 'Ad Group Location Criterion': _EntityInfo(lambda: BulkAdGroupLocationCriterion()), - 'Ad Group Location Intent Criterion': _EntityInfo(lambda: BulkAdGroupLocationIntentCriterion()), - 'Ad Group Negative Location Criterion': _EntityInfo(lambda: BulkAdGroupNegativeLocationCriterion()), - 'Ad Group Radius Criterion': _EntityInfo(lambda: BulkAdGroupRadiusCriterion()), - _StringTable.CampaignAgeCriterion: _EntityInfo(lambda: BulkCampaignAgeCriterion()), - _StringTable.CampaignDayTimeCriterion: _EntityInfo(lambda: BulkCampaignDayTimeCriterion()), - _StringTable.CampaignDeviceOSCriterion: _EntityInfo(lambda: BulkCampaignDeviceCriterion()), - _StringTable.CampaignGenderCriterion: _EntityInfo(lambda: BulkCampaignGenderCriterion()), - _StringTable.CampaignLocationCriterion: _EntityInfo(lambda: BulkCampaignLocationCriterion()), - _StringTable.CampaignLocationIntentCriterion: _EntityInfo(lambda: BulkCampaignLocationIntentCriterion()), - _StringTable.CampaignNegativeLocationCriterion: _EntityInfo(lambda: BulkCampaignNegativeLocationCriterion()), - _StringTable.CampaignRadiusCriterion: _EntityInfo(lambda: BulkCampaignRadiusCriterion()), - _StringTable.CampaignCompanyNameCriterion: _EntityInfo(lambda: BulkCampaignCompanyNameCriterion()), - _StringTable.CampaignJobFunctionCriterion: _EntityInfo(lambda: BulkCampaignJobFunctionCriterion()), - _StringTable.CampaignIndustryCriterion: _EntityInfo(lambda: BulkCampaignIndustryCriterion()), - _StringTable.ProductAudience: _EntityInfo(lambda: BulkProductAudience()), - _StringTable.AdGroupProductAudienceAssociation: _EntityInfo(lambda: BulkAdGroupProductAudienceAssociation()), - _StringTable.AdGroupNegativeProductAudienceAssociation: _EntityInfo(lambda: BulkAdGroupNegativeProductAudienceAssociation()), - _StringTable.CampaignProductAudienceAssociation: _EntityInfo(lambda: BulkCampaignProductAudienceAssociation()), - _StringTable.CampaignNegativeProductAudienceAssociation: _EntityInfo(lambda: BulkCampaignNegativeProductAudienceAssociation()), - _StringTable.AdGroupIndustryCriterion: _EntityInfo(lambda: BulkAdGroupIndustryCriterion()), - _StringTable.AdGroupCompanyNameCriterion: _EntityInfo(lambda: BulkAdGroupCompanyNameCriterion()), - _StringTable.AdGroupJobFunctionCriterion: _EntityInfo(lambda: BulkAdGroupJobFunctionCriterion()), - _StringTable.AdGroupNegativeAgeCriterion: _EntityInfo(lambda: BulkAdGroupNegativeAgeCriterion()), - _StringTable.AdGroupNegativeCompanyNameCriterion: _EntityInfo(lambda: BulkAdGroupNegativeCompanyNameCriterion()), - _StringTable.AdGroupNegativeGenderCriterion: _EntityInfo(lambda: BulkAdGroupNegativeGenderCriterion()), - _StringTable.AdGroupNegativeIndustryCriterion: _EntityInfo(lambda: BulkAdGroupNegativeIndustryCriterion()), - _StringTable.AdGroupNegativeJobFunctionCriterion: _EntityInfo(lambda: BulkAdGroupNegativeJobFunctionCriterion()), - _StringTable.Label: _EntityInfo(lambda: BulkLabel()), - _StringTable.CampaignLabel: _EntityInfo(lambda: BulkCampaignLabel()), - _StringTable.AdGroupLabel: _EntityInfo(lambda: BulkAdGroupLabel()), - _StringTable.KeywordLabel: _EntityInfo(lambda: BulkKeywordLabel()), - _StringTable.AppInstallAdLabel: _EntityInfo(lambda: BulkAppInstallAdLabel()), - _StringTable.DynamicSearchAdLabel: _EntityInfo(lambda: BulkDynamicSearchAdLabel()), - _StringTable.ExpandedTextAdLabel: _EntityInfo(lambda: BulkExpandedTextAdLabel()), - _StringTable.ProductAdLabel: _EntityInfo(lambda: BulkProductAdLabel()), - _StringTable.ResponsiveAdLabel: _EntityInfo(lambda: BulkResponsiveAdLabel()), - _StringTable.ResponsiveSearchAdLabel: _EntityInfo(lambda: BulkResponsiveSearchAdLabel()), - _StringTable.OfflineConversion: _EntityInfo(lambda: BulkOfflineConversion()), - _StringTable.SimilarRemarketingList: _EntityInfo(lambda: BulkSimilarRemarketingList()), - _StringTable.AdGroupSimilarRemarketingListAssociation: _EntityInfo(lambda: BulkAdGroupSimilarRemarketingListAssociation()), - _StringTable.AdGroupNegativeSimilarRemarketingListAssociation: _EntityInfo(lambda: BulkAdGroupNegativeSimilarRemarketingListAssociation()), - _StringTable.CampaignSimilarRemarketingListAssociation: _EntityInfo(lambda: BulkCampaignSimilarRemarketingListAssociation()), - _StringTable.CampaignNegativeSimilarRemarketingListAssociation: _EntityInfo(lambda: BulkCampaignNegativeSimilarRemarketingListAssociation()), - _StringTable.ActionAdExtension: _EntityInfo(lambda: BulkActionAdExtension()), - _StringTable.AccountActionAdExtension: _EntityInfo(lambda: BulkAccountActionAdExtension()), - _StringTable.AdGroupActionAdExtension: _EntityInfo(lambda: BulkAdGroupActionAdExtension()), - _StringTable.CampaignActionAdExtension: _EntityInfo(lambda: BulkCampaignActionAdExtension()), - _StringTable.Experiment: _EntityInfo(lambda: BulkExperiment()), - } - - ADDITIONAL_OBJECT_MAP = { - 'Format Version': lambda: _FormatVersion(), - 'Keyword Best Position Bid': lambda: BulkKeywordBestPositionBid(), - 'Keyword Main Line Bid': lambda: BulkKeywordMainLineBid(), - 'Keyword First Page Bid': lambda: BulkKeywordFirstPageBid(), - } - - TYPE_REVERSE_MAP = {} - TARGET_IDENTIFIER_TYPE_REVERSE_MAP = {} - - @staticmethod - def create_bulk_object(row_values): - type_column = row_values[_StringTable.Type] - - if type_column.endswith('Error'): - return BulkError() - elif type_column in _BulkObjectFactory.ADDITIONAL_OBJECT_MAP: - return _BulkObjectFactory.ADDITIONAL_OBJECT_MAP[type_column]() - elif type_column in _BulkObjectFactory.INDIVIDUAL_ENTITY_MAP: - info = _BulkObjectFactory.INDIVIDUAL_ENTITY_MAP[type_column] - if row_values[_StringTable.Status] == 'Deleted' \ - and info.delete_all_column_name \ - and not row_values[info.delete_all_column_name]: - return info.create_identifier_func() - return info.create_func() - else: - return UnknownBulkEntity() - - @staticmethod - def get_bulk_row_type(bulk_object): - if isinstance(bulk_object, BulkError): - return '{0} Error'.format(_BulkObjectFactory.get_bulk_row_type(bulk_object.entity)) - return _BulkObjectFactory.TYPE_REVERSE_MAP[type(bulk_object)] - - -for (k, v) in _BulkObjectFactory.INDIVIDUAL_ENTITY_MAP.items(): - _BulkObjectFactory.TYPE_REVERSE_MAP[type(v.create_func())] = k - - if v.create_identifier_func is not None: - identifier = v.create_identifier_func() - _BulkObjectFactory.TYPE_REVERSE_MAP[type(identifier)] = k diff --git a/bingads/v12/internal/bulk/csv_headers.py b/bingads/v12/internal/bulk/csv_headers.py deleted file mode 100644 index 8af41f1f..00000000 --- a/bingads/v12/internal/bulk/csv_headers.py +++ /dev/null @@ -1,351 +0,0 @@ -from .string_table import _StringTable - - -class _CsvHeaders: - HEADERS = [ - # Common - _StringTable.Type, - _StringTable.Status, - _StringTable.Id, - _StringTable.ParentId, - _StringTable.SubType, - _StringTable.Campaign, - _StringTable.AdGroup, - _StringTable.Website, - _StringTable.SyncTime, - _StringTable.ClientId, - _StringTable.LastModifiedTime, - - # Campaign - _StringTable.TimeZone, - _StringTable.Budget, - _StringTable.BudgetType, - _StringTable.BudgetName, - _StringTable.BudgetId, - - # AdGroup - _StringTable.StartDate, - _StringTable.EndDate, - _StringTable.NetworkDistribution, - _StringTable.AdRotation, - _StringTable.CpcBid, - _StringTable.Language, - _StringTable.PrivacyStatus, - - # Ads - _StringTable.Title, - _StringTable.Text, - _StringTable.TextPart2, - _StringTable.DisplayUrl, - _StringTable.DestinationUrl, - _StringTable.BusinessName, - _StringTable.PhoneNumber, - _StringTable.PromotionalText, - _StringTable.EditorialStatus, - _StringTable.EditorialLocation, - _StringTable.EditorialTerm, - _StringTable.EditorialReasonCode, - _StringTable.EditorialAppealStatus, - _StringTable.DevicePreference, - - # Keywords - _StringTable.Keyword, - _StringTable.MatchType, - _StringTable.Bid, - _StringTable.Param1, - _StringTable.Param2, - _StringTable.Param3, - - # Location Target - _StringTable.Target, - _StringTable.PhysicalIntent, - _StringTable.TargetAll, - _StringTable.BidAdjustment, - _StringTable.RadiusTargetId, - _StringTable.Name, - _StringTable.OsNames, - _StringTable.Radius, - _StringTable.Unit, - _StringTable.BusinessId, - - # DayTime Target - _StringTable.FromHour, - _StringTable.FromMinute, - _StringTable.ToHour, - _StringTable.ToMinute, - - # Profile Criterion - _StringTable.Profile, - _StringTable.ProfileId, - - # AdExtensions common - _StringTable.Version, - - # SiteLink Ad Extensions - _StringTable.SiteLinkExtensionOrder, - _StringTable.SiteLinkDisplayText, - _StringTable.SiteLinkDestinationUrl, - _StringTable.SiteLinkDescription1, - _StringTable.SiteLinkDescription2, - - # Location Ad Extensions - _StringTable.GeoCodeStatus, - _StringTable.ImageMediaId, - _StringTable.AddressLine1, - _StringTable.AddressLine2, - _StringTable.PostalCode, - _StringTable.City, - _StringTable.StateOrProvince, - _StringTable.ProvinceName, - _StringTable.Latitude, - _StringTable.Longitude, - - # Call Ad Extensions - _StringTable.CountryCode, - _StringTable.IsCallOnly, - _StringTable.IsCallTrackingEnabled, - _StringTable.RequireTollFreeTrackingNumber, - - # Structured Snippet Ad Extensions - _StringTable.StructuredSnippetHeader, - _StringTable.StructuredSnippetValues, - - # Image Ad Extensions - _StringTable.AltText, - _StringTable.MediaIds, - _StringTable.PublisherCountries, - - # Callout Ad Extension - _StringTable.CalloutText, - - # Product Target - _StringTable.BingMerchantCenterId, - _StringTable.BingMerchantCenterName, - _StringTable.ProductCondition1, - _StringTable.ProductValue1, - _StringTable.ProductCondition2, - _StringTable.ProductValue2, - _StringTable.ProductCondition3, - _StringTable.ProductValue3, - _StringTable.ProductCondition4, - _StringTable.ProductValue4, - _StringTable.ProductCondition5, - _StringTable.ProductValue5, - _StringTable.ProductCondition6, - _StringTable.ProductValue6, - _StringTable.ProductCondition7, - _StringTable.ProductValue7, - _StringTable.ProductCondition8, - _StringTable.ProductValue8, - - # BI - _StringTable.Spend, - _StringTable.Impressions, - _StringTable.Clicks, - _StringTable.CTR, - _StringTable.AvgCPC, - _StringTable.AvgCPM, - _StringTable.AvgPosition, - _StringTable.Conversions, - _StringTable.CPA, - - _StringTable.QualityScore, - _StringTable.KeywordRelevance, - _StringTable.LandingPageRelevance, - _StringTable.LandingPageUserExperience, - - _StringTable.AppPlatform, - _StringTable.AppStoreId, - _StringTable.IsTrackingEnabled, - - _StringTable.Error, - _StringTable.ErrorNumber, - - # Bing Shopping Campaigns - _StringTable.IsExcluded, - _StringTable.ParentAdGroupCriterionId, - _StringTable.CampaignType, - _StringTable.CampaignPriority, - _StringTable.LocalInventoryAdsEnabled, - - # experiment - _StringTable.TrafficSplitPercent, - _StringTable.BaseCampaignId, - _StringTable.ExperimentCampaignId, - _StringTable.ExperimentId, - _StringTable.ExperimentType, - - #CoOp - _StringTable.BidOption, - _StringTable.BidBoostValue, - _StringTable.MaximumBid, - - # V10 added - _StringTable.FieldPath, - - # Upgrade Url - _StringTable.FinalUrl, - _StringTable.FinalMobileUrl, - _StringTable.TrackingTemplate, - _StringTable.CustomParameter, - - # Review Ad Extension - _StringTable.IsExact, - _StringTable.Source, - _StringTable.Url, - - # Price Ad Extension - _StringTable.PriceExtensionType, - _StringTable.Header1, - _StringTable.Header2, - _StringTable.Header3, - _StringTable.Header4, - _StringTable.Header5, - _StringTable.Header6, - _StringTable.Header7, - _StringTable.Header8, - _StringTable.PriceDescription1, - _StringTable.PriceDescription2, - _StringTable.PriceDescription3, - _StringTable.PriceDescription4, - _StringTable.PriceDescription5, - _StringTable.PriceDescription6, - _StringTable.PriceDescription7, - _StringTable.PriceDescription8, - _StringTable.FinalUrl1, - _StringTable.FinalUrl2, - _StringTable.FinalUrl3, - _StringTable.FinalUrl4, - _StringTable.FinalUrl5, - _StringTable.FinalUrl6, - _StringTable.FinalUrl7, - _StringTable.FinalUrl8, - _StringTable.FinalMobileUrl1, - _StringTable.FinalMobileUrl2, - _StringTable.FinalMobileUrl3, - _StringTable.FinalMobileUrl4, - _StringTable.FinalMobileUrl5, - _StringTable.FinalMobileUrl6, - _StringTable.FinalMobileUrl7, - _StringTable.FinalMobileUrl8, - _StringTable.Price1, - _StringTable.Price2, - _StringTable.Price3, - _StringTable.Price4, - _StringTable.Price5, - _StringTable.Price6, - _StringTable.Price7, - _StringTable.Price8, - _StringTable.CurrencyCode1, - _StringTable.CurrencyCode2, - _StringTable.CurrencyCode3, - _StringTable.CurrencyCode4, - _StringTable.CurrencyCode5, - _StringTable.CurrencyCode6, - _StringTable.CurrencyCode7, - _StringTable.CurrencyCode8, - _StringTable.PriceUnit1, - _StringTable.PriceUnit2, - _StringTable.PriceUnit3, - _StringTable.PriceUnit4, - _StringTable.PriceUnit5, - _StringTable.PriceUnit6, - _StringTable.PriceUnit7, - _StringTable.PriceUnit8, - _StringTable.PriceQualifier1, - _StringTable.PriceQualifier2, - _StringTable.PriceQualifier3, - _StringTable.PriceQualifier4, - _StringTable.PriceQualifier5, - _StringTable.PriceQualifier6, - _StringTable.PriceQualifier7, - _StringTable.PriceQualifier8, - - # Bid Strategy - _StringTable.BidStrategyType, - _StringTable.BidStrategyMaxCpc, - _StringTable.BidStrategyTargetCpa, - _StringTable.InheritedBidStrategyType, - - # Ad Format Preference - _StringTable.AdFormatPreference, - - # Remarketing - _StringTable.Audience, - _StringTable.Description, - _StringTable.MembershipDuration, - _StringTable.Scope, - _StringTable.TagId, - _StringTable.AudienceId, - _StringTable.TargetSetting, - _StringTable.RemarketingRule, - _StringTable.AudienceSearchSize, - _StringTable.AudienceNetworkSize, - _StringTable.SupportedCampaignTypes, - _StringTable.ProductAudienceType, - _StringTable.SourceId, - - - # Expanded Text Ad - _StringTable.TitlePart1, - _StringTable.TitlePart2, - _StringTable.TitlePart3, - _StringTable.Path1, - _StringTable.Path2, - _StringTable.Domain, - - # Responsive Ad - _StringTable.CallToAction, - _StringTable.Headline, - _StringTable.Images, - _StringTable.LandscapeImageMediaId, - _StringTable.LandscapeLogoMediaId, - _StringTable.LongHeadline, - _StringTable.SquareImageMediaId, - _StringTable.SquareLogoMediaId, - - # Ad Scheduling - _StringTable.AdSchedule, - _StringTable.UseSearcherTimeZone, - - # Action ad extension - _StringTable.ActionType, - _StringTable.ActionText, - - # Dynamic Search Ads - _StringTable.DomainLanguage, - _StringTable.DynamicAdTargetCondition1, - _StringTable.DynamicAdTargetValue1, - _StringTable.DynamicAdTargetCondition2, - _StringTable.DynamicAdTargetValue2, - _StringTable.DynamicAdTargetCondition3, - _StringTable.DynamicAdTargetValue3, - - # Labels - _StringTable.ColorCode, - _StringTable.Label, - - # Offline Conversions - _StringTable.ConversionCurrencyCode, - _StringTable.ConversionName, - _StringTable.ConversionTime, - _StringTable.ConversionValue, - _StringTable.MicrosoftClickId, - - # Account - _StringTable.MSCLKIDAutoTaggingEnabled, - - _StringTable.FinalUrlSuffix, - - ] - - @staticmethod - def get_mappings(): - return _CsvHeaders.COLUMN_INDEX_MAP - - @staticmethod - def initialize_map(): - return dict(zip(_CsvHeaders.HEADERS, range(len(_CsvHeaders.HEADERS)))) - - -_CsvHeaders.COLUMN_INDEX_MAP = _CsvHeaders.initialize_map() diff --git a/bingads/v12/internal/bulk/csv_reader.py b/bingads/v12/internal/bulk/csv_reader.py deleted file mode 100644 index 83a05302..00000000 --- a/bingads/v12/internal/bulk/csv_reader.py +++ /dev/null @@ -1,59 +0,0 @@ -import csv -import io -from six import PY2, PY3 - -class _CsvReader: - - def __init__(self, filename, delimiter, encoding='utf-8-sig'): - self._filename = filename - self._delimiter = delimiter - self._encoding = encoding - - if delimiter == ',': - self._dialect = csv.excel - elif delimiter == '\t': - self._dialect = csv.excel_tab - else: - raise ValueError('Do not support delimiter: {0}', delimiter) - - self._csv_file = io.open(self.filename, encoding=self.encoding) - - if PY3: - self._csv_reader = csv.reader(self._csv_file, dialect=self._dialect) - elif PY2: - byte_lines = [line.encode('utf-8') for line in self._csv_file] - self._csv_reader = csv.reader(byte_lines, dialect=self._dialect) - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._csv_file.__exit__(exc_type, exc_value, traceback) - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def close(self): - self.__exit__(None, None, None) - - def next(self): - if PY3: - return next(self._csv_reader) - elif PY2: - row = next(self._csv_reader) - return [unicode(cell, encoding='utf-8') for cell in row] - - @property - def filename(self): - return self._filename - - @property - def delimiter(self): - return self._delimiter - - @property - def encoding(self): - return self._encoding diff --git a/bingads/v12/internal/bulk/csv_writer.py b/bingads/v12/internal/bulk/csv_writer.py deleted file mode 100644 index 5d8c4ff4..00000000 --- a/bingads/v12/internal/bulk/csv_writer.py +++ /dev/null @@ -1,56 +0,0 @@ -import csv -import codecs -from six import PY2, PY3 - - -class _CsvWriter: - def __init__(self, filename, delimiter): - self._filename = filename - self._delimiter = delimiter - self._encoding = 'utf-8-sig' - - if delimiter == ',': - self._dialect = csv.excel - elif delimiter == '\t': - self._dialect = csv.excel_tab - else: - raise ValueError('Do not support delimiter: {0}', delimiter) - - if PY3: - self._csv_file = codecs.open(filename, mode='w', encoding=self._encoding) - elif PY2: - self._csv_file = open(filename, mode='wb') - self._csv_file.write(codecs.BOM_UTF8) - self._csv_writer = csv.writer(self._csv_file, dialect=self._dialect) - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - self._csv_file.flush() - self._csv_file.close() - - def close(self): - self.__exit__(None, None, None) - - def writerow(self, row): - if PY3: - self._csv_writer.writerow(row) - elif PY2: - def unicode_to_str(value): - if not isinstance(value, unicode): - return value - return value.encode('utf-8') - self._csv_writer.writerow([unicode_to_str(cell) for cell in row]) - - def writerows(self, rows): - for row in rows: - self.writerow(row) - - @property - def filename(self): - return self._filename - - @property - def delimiter(self): - return self._delimiter diff --git a/bingads/v12/internal/bulk/entities/__init__.py b/bingads/v12/internal/bulk/entities/__init__.py deleted file mode 100644 index 5ae46b47..00000000 --- a/bingads/v12/internal/bulk/entities/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - diff --git a/bingads/v12/internal/bulk/entities/bulk_entity_identifier.py b/bingads/v12/internal/bulk/entities/bulk_entity_identifier.py deleted file mode 100644 index 813dacf0..00000000 --- a/bingads/v12/internal/bulk/entities/bulk_entity_identifier.py +++ /dev/null @@ -1,35 +0,0 @@ -from __future__ import absolute_import, division, print_function -from abc import ABCMeta, abstractproperty, abstractmethod - -from future.utils import with_metaclass - -from bingads.v12.bulk.entities import BulkError -from bingads.v12.internal.bulk.bulk_object import _BulkObject - - -class _BulkEntityIdentifier(with_metaclass(ABCMeta, _BulkObject)): - - @abstractproperty - def is_delete_row(self): - raise NotImplementedError() - - @abstractmethod - def _create_entity_with_this_identifier(self): - raise NotImplementedError() - - def write_to_stream(self, row_writer, exclude_readonly_data): - row_writer.write_object_row(self) - - def read_related_data_from_stream(self, stream_reader): - if self.is_delete_row: - has_more_errors = True - - while has_more_errors: - has_more_errors, error = stream_reader.try_read(BulkError) - - @property - def can_enclose_in_multiline_entity(self): - return True - - def enclose_in_multiline_entity(self): - return self._create_entity_with_this_identifier() diff --git a/bingads/v12/internal/bulk/entities/multi_record_bulk_entity.py b/bingads/v12/internal/bulk/entities/multi_record_bulk_entity.py deleted file mode 100644 index 9eae1755..00000000 --- a/bingads/v12/internal/bulk/entities/multi_record_bulk_entity.py +++ /dev/null @@ -1,64 +0,0 @@ -from abc import ABCMeta, abstractproperty -from future.utils import with_metaclass -from bingads.v12.bulk.entities.bulk_entity import BulkEntity - - -class _MultiRecordBulkEntity(with_metaclass(ABCMeta, BulkEntity)): - """ Bulk entity that has its data in multiple records within the bulk file. - - For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127. - """ - - def __init__(self): - super(_MultiRecordBulkEntity, self).__init__() - - @abstractproperty - def child_entities(self): - """ The child entities that this multi record entity contains. - - :rtype: list[BulkEntity] - """ - - raise NotImplementedError() - - @abstractproperty - def all_children_are_present(self): - """ True, if the object is fully constructed (contains all of its children), determined by the presence of delete all row, False otherwise - - :rtype: bool - """ - - raise NotImplementedError() - - @property - def has_errors(self): - """ Indicates whether or not the errors property of any of the ChildEntities is null or empty. - - If true, one or more ChildEntities contains the details of one or more :class:`.BulkError` objects. - - :rtype: bool - """ - - return any(map(lambda x: x.has_errors, self.child_entities)) - - @property - def last_modified_time(self): - """ Gets the last modified time for the first child entity, or null if there are no ChildEntities. - - :rtype: datetime.datetime - """ - - return self.child_entities[0].last_modified_time if self.child_entities else None - - @property - def can_enclose_in_multiline_entity(self): - return super(_MultiRecordBulkEntity, self).can_enclose_in_multiline_entity - - def enclose_in_multiline_entity(self): - return super(_MultiRecordBulkEntity, self).enclose_in_multiline_entity() - - def read_from_row_values(self, row_values): - super(_MultiRecordBulkEntity, self).read_from_row_values(row_values) - - def write_to_row_values(self, row_values): - super(_MultiRecordBulkEntity, self).write_to_row_values(row_values) diff --git a/bingads/v12/internal/bulk/entities/single_record_bulk_entity.py b/bingads/v12/internal/bulk/entities/single_record_bulk_entity.py deleted file mode 100644 index de20db55..00000000 --- a/bingads/v12/internal/bulk/entities/single_record_bulk_entity.py +++ /dev/null @@ -1,124 +0,0 @@ -from abc import ABCMeta, abstractmethod - -from future.utils import with_metaclass - -from bingads.v12.internal.bulk.string_table import _StringTable -from bingads.v12.internal.bulk.mappings import _SimpleBulkMapping -from bingads.v12.bulk.entities.bulk_entity import BulkEntity -from bingads.v12.bulk.entities.bulk_error import BulkError -from bingads.v12.internal.extensions import * - - -class _SingleRecordBulkEntity(with_metaclass(ABCMeta, BulkEntity)): - def __init__(self): - self._client_id = None - self._last_modified_time = None - self._errors = None - - @property - def client_id(self): - return self._client_id - - @client_id.setter - def client_id(self, client_id): - self._client_id = client_id - - @property - def last_modified_time(self): - return self._last_modified_time - - @property - def errors(self): - """ A list of :class:`BulkError` details in a separate bulk record that corresponds to the record of a :class:`.BulkEntity` derived instance. - - :rtype: list[BulkError] or None - """ - return self._errors - - @property - def has_errors(self): - return True if self.errors is not None and self.errors else False - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.ClientId, - field_to_csv=lambda c: c.client_id, - csv_to_field=lambda c, v: setattr(c, '_client_id', v), - ), - _SimpleBulkMapping( - header=_StringTable.LastModifiedTime, - field_to_csv=lambda c: bulk_datetime_str(c.last_modified_time), - csv_to_field=lambda c, v: setattr( - c, - '_last_modified_time', - parse_datetime(v) if v else None), - ), - ] - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, _SingleRecordBulkEntity._MAPPINGS) - self.process_mappings_from_row_values(row_values) - - def write_to_row_values(self, row_values, exclude_readonly_data): - self.convert_to_values(row_values, _SingleRecordBulkEntity._MAPPINGS) - self.process_mappings_to_row_values(row_values, exclude_readonly_data) - - def read_related_data_from_stream(self, stream_reader): - self.read_additional_data(stream_reader) - self._read_errors(stream_reader) - - def write_to_stream(self, row_writer, exclude_readonly_data): - row_writer.write_object_row(self, exclude_readonly_data) - if not exclude_readonly_data: - self._write_errors(row_writer) - self.write_additional_data(row_writer) - - def _write_errors(self, row_writer): - if self.has_errors: - for error in self.errors: - row_writer.write_object_row(error) - - def write_additional_data(self, row_writer): - pass - - @abstractmethod - def process_mappings_to_row_values(self, row_values, exclude_readonly_data): - """ Process specific entity mappings to CSV values. Must be implemented by each entity. - - :param row_values: Row values. - :type row_values: _RowValues - :param exclude_readonly_data: excludeReadonlyData indicates whether readonly data should be written (such as errors, performance data etc.) - :type exclude_readonly_data: bool - """ - - raise NotImplementedError() - - @abstractmethod - def process_mappings_from_row_values(self, row_values): - """ Process specific entity mappings from CSV values. Must be implemented by each entity. - - :param row_values: - :type row_values: _RowValues - """ - - raise NotImplementedError() - - @abstractmethod - def read_additional_data(self, stream_reader): - pass - - def _read_errors(self, stream_reader): - errors = [] - success, error = stream_reader.try_read(BulkError) - while success: - error.entity = self - errors.append(error) - success, error = stream_reader.try_read(BulkError) - self._errors = errors - - def enclose_in_multiline_entity(self): - return super(_SingleRecordBulkEntity, self).enclose_in_multiline_entity() - - @property - def can_enclose_in_multiline_entity(self): - return super(_SingleRecordBulkEntity, self).can_enclose_in_multiline_entity diff --git a/bingads/v12/internal/bulk/entity_info.py b/bingads/v12/internal/bulk/entity_info.py deleted file mode 100644 index e9243f60..00000000 --- a/bingads/v12/internal/bulk/entity_info.py +++ /dev/null @@ -1,5 +0,0 @@ -class _EntityInfo: - def __init__(self, create_func, delete_all_column_name=None, create_identifier_func=None): - self.create_func = create_func - self.delete_all_column_name = delete_all_column_name - self.create_identifier_func = create_identifier_func diff --git a/bingads/v12/internal/bulk/format_version.py b/bingads/v12/internal/bulk/format_version.py deleted file mode 100644 index afad9d54..00000000 --- a/bingads/v12/internal/bulk/format_version.py +++ /dev/null @@ -1,38 +0,0 @@ -from .bulk_object import _BulkObject -from .string_table import _StringTable -from .mappings import _SimpleBulkMapping - - -class _FormatVersion(_BulkObject): - def __init__(self): - self._value = None - - @property - def value(self): - return self._value - - _MAPPINGS = [ - _SimpleBulkMapping( - header=_StringTable.Name, - csv_to_field=lambda c, v: setattr(c, "_value", v) - ) - ] - - def read_from_row_values(self, row_values): - row_values.convert_to_entity(self, _FormatVersion._MAPPINGS) - - def write_to_row_values(self, row_values): - super(_FormatVersion, self).write_to_row_values(row_values) - - def read_related_data_from_stream(self, stream_reader): - super(_FormatVersion, self).read_related_data_from_stream(stream_reader) - - def write_to_stream(self, row_writer): - super(_FormatVersion, self).write_to_stream(row_writer) - - @property - def can_enclose_in_multiline_entity(self): - return super(_FormatVersion, self).can_enclose_in_multiline_entity - - def enclose_in_multiline_entity(self): - return super(_FormatVersion, self).enclose_in_multiline_entity() diff --git a/bingads/v12/internal/bulk/mappings.py b/bingads/v12/internal/bulk/mappings.py deleted file mode 100644 index 24b4cdc3..00000000 --- a/bingads/v12/internal/bulk/mappings.py +++ /dev/null @@ -1,116 +0,0 @@ -from future.utils import with_metaclass -from abc import ABCMeta, abstractmethod - - -class _BulkMapping(with_metaclass(ABCMeta)): - @abstractmethod - def convert_to_csv(self, entity, row_values): - raise NotImplementedError() - - @abstractmethod - def convert_to_entity(self, row_values, entity): - raise NotImplementedError() - - -class _SingleFieldBulkMapping(with_metaclass(ABCMeta, _BulkMapping)): - def __init__(self, csv_to_field, filed_to_csv): - self._csv_to_field = csv_to_field - self._field_to_csv = filed_to_csv - - @property - def csv_to_field(self): - """ - - :rtype: str -> T - """ - - return self._csv_to_field - - @property - def field_to_csv(self): - """ - - :rtype: T -> str - :return: - """ - return self._field_to_csv - - def convert_to_csv(self, entity, row_values): - if self.field_to_csv is None: - return None - row_values[self.parse_header(entity)] = self.field_to_csv(entity) - - def convert_to_entity(self, row_values, entity): - # Bulk file can have fewer column than SDK knows, so to have the ability to read old file, if cannot find column - # just return None for that column, if it is mandatory, then will throw exception later, if not, then pass. - - self.csv_to_field(entity, row_values.try_get_value(self.parse_header(entity))[1]) - - @abstractmethod - def parse_header(self, entity): - raise NotImplementedError() - - -class _SimpleBulkMapping(_SingleFieldBulkMapping): - def __init__(self, header, csv_to_field, field_to_csv=None): - super(_SimpleBulkMapping, self).__init__(csv_to_field, field_to_csv) - self._header = header - - @property - def header(self): - """ - - :rtype: str - - """ - return self._header - - def parse_header(self, entity): - return self.header - - -class _DynamicColumnNameMapping(_SingleFieldBulkMapping): - def __init__(self, header_func, csv_to_field, field_to_csv=None): - super(_DynamicColumnNameMapping, self).__init__(csv_to_field, field_to_csv) - self._header_func = header_func - - @property - def header_func(self): - """ - - :rtype: T -> str - """ - return self._header_func - - def parse_header(self, entity): - return self.header_func(entity) - - -class _ComplexBulkMapping(_BulkMapping): - def __init__(self, entity_to_csv, csv_to_entity): - self._entity_to_csv = entity_to_csv - self._csv_to_entity = csv_to_entity - - @property - def csv_to_entity(self): - """ - - :rtype: _RowValues -> T - """ - - return self._csv_to_entity - - @property - def entity_to_csv(self): - """ - - :rtype: T -> _RowValues - """ - - return self._entity_to_csv - - def convert_to_csv(self, entity, row_values): - self.entity_to_csv(entity, row_values) - - def convert_to_entity(self, row_values, entity): - self.csv_to_entity(row_values, entity) diff --git a/bingads/v12/internal/bulk/object_reader.py b/bingads/v12/internal/bulk/object_reader.py deleted file mode 100644 index f8b8edfa..00000000 --- a/bingads/v12/internal/bulk/object_reader.py +++ /dev/null @@ -1,75 +0,0 @@ -from .bulk_object_factory import _BulkObjectFactory -from .row_values import _RowValues -from .csv_reader import _CsvReader - -class _BulkObjectReader(): - """ Provides a method to read one row from bulk file and return the corresponding :class:`._BulkObject` """ - - def __init__(self, file_path, delimiter, encoding='utf-8-sig'): - self._file_path = file_path - self._delimiter = delimiter - self._encoding = encoding - - self._csv_reader = _CsvReader(self.file_path, delimiter=self.delimiter, encoding=self._encoding) - self._csv_reader.__enter__() - headers = self._read_headers() - self._column_mapping = dict(zip(headers, range(0, len(headers)))) - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._csv_reader.__exit__(exc_type, exc_value, traceback) - - def __iter__(self): - return self - - def __next__(self): - return self.read_next_bulk_object() - - def next(self): - return self.__next__() - - def read_next_bulk_object(self): - """ Reads the next csv row values, creates a new instance of the object and populates it with the row values. - - :return: next bulk object - :rtype: _BulkObject - """ - try: - row_values = self._read_next_row_values() - except StopIteration: - return None - bulk_object = _BulkObjectFactory.create_bulk_object(row_values) - bulk_object.read_from_row_values(row_values) - return bulk_object - - def close(self): - self.__exit__(None, None, None) - - def _read_next_row_values(self): - values = next(self._csv_reader) - return _RowValues(columns=values, mappings=self._column_mapping) - - def _read_headers(self): - # Need to strip BOM marker by hand, take care - def remove_bom(unicode_str): - unicode_bom = u'\N{ZERO WIDTH NO-BREAK SPACE}' - if unicode_str and unicode_str[0] == unicode_bom: - unicode_str = unicode_str[1:] - return unicode_str - - headers = next(self._csv_reader) - return [remove_bom(header) for header in headers] - - @property - def file_path(self): - return self._file_path - - @property - def delimiter(self): - return self._delimiter - - @property - def encoding(self): - return self._encoding diff --git a/bingads/v12/internal/bulk/object_writer.py b/bingads/v12/internal/bulk/object_writer.py deleted file mode 100644 index 474847bd..00000000 --- a/bingads/v12/internal/bulk/object_writer.py +++ /dev/null @@ -1,58 +0,0 @@ -from bingads.manifest import BULK_FORMAT_VERSION_6 - -from bingads.v12.internal.bulk.bulk_object_factory import _BulkObjectFactory -from bingads.v12.internal.bulk.csv_writer import _CsvWriter -from bingads.v12.internal.bulk.csv_headers import _CsvHeaders -from bingads.v12.internal.bulk.row_values import _RowValues -from bingads.v12.internal.bulk.string_table import _StringTable - - -class _BulkObjectWriter(): - def __init__(self, file_path, file_type): - self._file_path = file_path - - if file_type == 'Csv': - self._delimiter = ',' - elif file_type == 'Tsv': - self._delimiter = '\t' - else: - raise ValueError('Invalid file_type provided: {0}'.format(file_type)) - - self._csv_writer = _CsvWriter(self.file_path, delimiter=self._delimiter) - self._csv_writer.__enter__() - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self._csv_writer.__exit__(exc_type, exc_val, exc_tb) - - def close(self): - self.__exit__(None, None, None) - - def write_file_metadata(self): - self.write_headers() - self.write_format_version() - - def write_headers(self): - self._csv_writer.writerow(_CsvHeaders.HEADERS) - - def write_format_version(self): - version_row = _RowValues() - version_row[_StringTable.Type] = _StringTable.SemanticVersion - version_row[_StringTable.Name] = BULK_FORMAT_VERSION_6 - self._csv_writer.writerow(version_row.columns) - - def write_object_row(self, bulk_object, exclude_readonly_data=False): - values = _RowValues() - bulk_object.write_to_row_values(values, exclude_readonly_data) - values[_StringTable.Type] = _BulkObjectFactory.get_bulk_row_type(bulk_object) - self._csv_writer.writerow(values.columns) - - @property - def file_path(self): - return self._file_path - - @property - def delimiter(self): - return self._delimiter diff --git a/bingads/v12/internal/bulk/row_values.py b/bingads/v12/internal/bulk/row_values.py deleted file mode 100644 index 2f503102..00000000 --- a/bingads/v12/internal/bulk/row_values.py +++ /dev/null @@ -1,70 +0,0 @@ -from .csv_headers import _CsvHeaders -from .mappings import _SimpleBulkMapping -from bingads.v12.bulk import EntityReadException -import six - - -class _RowValues: - def __init__(self, mappings=None, columns=None): - self._mappings = mappings - self._columns = columns - if self.mappings is None: - self._mappings = _CsvHeaders.get_mappings() - if self.columns is None: - self._columns = [None] * len(self._mappings) - - def __getitem__(self, key): - return self.columns[self._mappings[key]] - - def __setitem__(self, key, value): - self.columns[self._mappings[key]] = value - - def __contains__(self, item): - return item in self.mappings - - def __len__(self): - return len(self.mappings) - - def __str__(self): - return u'{' + u', '.join([u'{0}:{1}'.format(k, self.columns[v]) for (k, v) in self.mappings.items()]) + u'}' - - def convert_to_entity(self, entity, bulk_mappings): - for mapping in bulk_mappings: - try: - mapping.convert_to_entity(self, entity) - except Exception as ex: - raise self._create_entity_read_exception(entity, mapping, ex) - - def _create_entity_read_exception(self, entity, mapping, ex): - entity_type = str(type(entity)) - - if isinstance(mapping, _SimpleBulkMapping): - message = "Couldn't parse column {0} of {1} entity: {2}".format( - mapping.header, - entity_type, - str(ex) - ) - else: - message = "Couldn't parse {0} entity: {1}".format(entity_type, str(ex)) - message += " See ColumnValues for detailed row information and InnerException for error details." - if six.PY2: - message = message.decode('ascii') - message += u' row values: {0}'.format(self) - - return EntityReadException(message=message, row_values=str(self), inner_exception=ex) - - def try_get_value(self, header): - if header not in self.mappings: - return False, None - return True, self[header] - - def to_dict(self): - return dict([(k, self.columns[v]) for (k, v) in self.mappings.items()]) - - @property - def mappings(self): - return self._mappings - - @property - def columns(self): - return self._columns diff --git a/bingads/v12/internal/bulk/stream_reader.py b/bingads/v12/internal/bulk/stream_reader.py deleted file mode 100644 index 77c1b2fc..00000000 --- a/bingads/v12/internal/bulk/stream_reader.py +++ /dev/null @@ -1,97 +0,0 @@ -from .bulk_object import _BulkObject -from .format_version import _FormatVersion -from .object_reader import _BulkObjectReader -from bingads.internal.error_messages import _ErrorMessages - - -class _BulkStreamReader(): - """ Reads a bulk object and also its related data (for example corresponding errors) from the stream.""" - - __SUPPORTED_VERSIONS = ["6", "6.0"] - - def __init__(self, file_path, file_type, encoding='utf-8-sig'): - self._file_path = file_path - self._file_type = file_type - self._encoding = encoding - - self._delimiter = ',' if self.file_type == 'Csv' else '\t' - self._passed_first_row = False - self._bulk_object_reader = _BulkObjectReader(self.file_path, self.delimiter, encoding=self._encoding) - self._bulk_object_reader.__enter__() - self._next_object = None - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self._bulk_object_reader.__exit__(exc_type, exc_val, exc_tb) - - def __iter__(self): - return self - - def __next__(self): - return self.read() - - def close(self): - self.__exit__(None, None, None) - - def next(self): - return self.__next__() - - def read(self): - """ Returns the next object from the file - - :return: next object - :rtype: :class:`._BulkObject` - """ - - _, bulk_object = self.try_read(_BulkObject) - return bulk_object - - def try_read(self, return_type, predicate=lambda x: True): - """ Reads the object only if it has a certain type - - :param return_type: The type of object that should be returned - :type return_type: class - :param predicate: A test that should be run against the object - :type predicate: function accepting on argument of the BulkObject - :return: an object of the type specified - :rtype: (bool, _BulkObject) - """ - peeked = self._peek() - if peeked is not None and isinstance(peeked, return_type) and predicate(peeked): - self._next_object = None - peeked.read_related_data_from_stream(self) - return True, peeked - return False, None - - def _peek(self): - if not self._passed_first_row: - first_row_object = self._bulk_object_reader.read_next_bulk_object() - if isinstance(first_row_object, _FormatVersion): - if first_row_object.value not in _BulkStreamReader.__SUPPORTED_VERSIONS: - raise NotImplementedError( - _ErrorMessages.get_format_version_not_supported_message(str(first_row_object.value))) - else: - self._next_object = first_row_object - self._passed_first_row = True - if self._next_object is not None: - return self._next_object - self._next_object = self._bulk_object_reader.read_next_bulk_object() - return self._next_object - - @property - def file_path(self): - return self._file_path - - @property - def file_type(self): - return self._file_type - - @property - def delimiter(self): - return self._delimiter - - @property - def encoding(self): - return self._encoding diff --git a/bingads/v12/internal/bulk/string_table.py b/bingads/v12/internal/bulk/string_table.py deleted file mode 100644 index 5b29eed0..00000000 --- a/bingads/v12/internal/bulk/string_table.py +++ /dev/null @@ -1,471 +0,0 @@ -class _StringTable: - # CSV Header Strings - ClientId = "Client Id" - Type = "Type" - Status = "Status" - Campaign = "Campaign" - Id = "Id" - BusinessId = "Business Id" - ParentId = "Parent Id" - TimeZone = "Time Zone" - Budget = "Budget" - BudgetType = "Budget Type" - BudgetName = "Budget Name" - Experiment = "Experiment" - TrafficSplitPercent = "Traffic Split Percent" - BaseCampaignId = "Base Campaign Id" - ExperimentCampaignId = "Experiment Campaign Id" - ExperimentId = "Experiment Id" - ExperimentType = "Experiment Type" - BudgetId = "Budget Id" - AdGroup = "Ad Group" - Keyword = "Keyword" - TextAd = "Text Ad" - ProductAd = "Product Ad" - AppInstallAd = "App Install Ad" - DynamicSearchAd = "Dynamic Search Ad" - ExpandedTextAd = "Expanded Text Ad" - Title = "Title" - EditorialStatus = "Editorial Status" - EditorialAppealStatus = "Editorial Appeal Status" - Error = "Error" - ErrorNumber = "Error Number" - EditorialLocation = "Editorial Location" - EditorialTerm = "Editorial Term" - EditorialReasonCode = "Editorial Reason Code" - MigrationErrors = "Migration Errors" - DisplayUrl = "Display Url" - DestinationUrl = "Destination Url" - BusinessName = "Business Name" - PhoneNumber = "Phone Number" - PromotionalText = "Promotion" - MatchType = "Match Type" - Param1 = "Param1" - Param2 = "Param2" - Param3 = "Param3" - DevicePreference = "Device Preference" - CampaignNegativeKeyword = "Campaign Negative Keyword" - CampaignNegativeSite = "Campaign Negative Site" - AdGroupNegativeKeyword = "Ad Group Negative Keyword" - KeywordNegativeKeyword = "Keyword Negative Keyword" - AdGroupNegativeSite = "Ad Group Negative Site" - Text = "Text" - TextPart2="Text Part 2" - Website = "Website" - Target = "Target" - PhysicalIntent = "Physical Intent" - Bid = "Bid" - Profile = "Profile" - ProfileId = "Profile Id" - BidAdjustment = "Bid Adjustment" - SubType = "Sub Type" - OsNames = "OS Names" - StartDate = "Start Date" - EndDate = "End Date" - NetworkDistribution = "Network Distribution" - Language = "Language" - CpcBid = "Cpc Bid" - AdRotation = "Ad Rotation" - PrivacyStatus = "Privacy Status" - Account = "Account" - SyncTime = "Sync Time" - Name = "Name" - MSCLKIDAutoTaggingEnabled = "MSCLKID Auto Tagging Enabled" - LastModifiedTime = "Modified Time" - AdFormatPreference = "Ad Format Preference" - - # Entity Types - SemanticVersion = "Format Version" - LocationTarget = "Location Target" - RadiusTarget = "Radius Target" - BusinessTarget = "Business Location Target" - RadiusTargetId = "Radius Target Id" - NegativeLocationTarget = "Negative Location Target" - AgeTarget = "Age Target" - GenderTarget = "Gender Target" - DeviceOsTarget = "DeviceOS Target" - Radius = "Radius" - Unit = "Unit" - TargetAll = "Target All" - LocationAdExtension = "Location Ad Extension" - CallAdExtension = "Call Ad Extension" - ImageAdExtension = "Image Ad Extension" - SocialNetworkAdExtension = "Social Network Ad Extension" - Version = "Version" - - # Image Ad Extension - AltText = "Alternative Text" - MediaIds = "Media Ids" - AccountImageAdExtension = "Account Image Ad Extension" - CampaignImageAdExtension = "Campaign Image Ad Extension" - AdGroupImageAdExtension = "Ad Group Image Ad Extension" - - # SiteLink Ad Extensions - SiteLinkExtensionOrder = "Sitelink Extension Order" - SiteLinkDisplayText = "Sitelink Extension Link Text" - SiteLinkDestinationUrl = "Sitelink Extension Destination Url" - SiteLinkDescription1 = "Sitelink Extension Description1" - SiteLinkDescription2 = "Sitelink Extension Description2" - - # Location Ad Extensions - AddressLine1 = "Address Line 1" - AddressLine2 = "Address Line 2" - PostalCode = "Postal Code" - City = "City" - StateOrProvince = "State Or Province Code" - ProvinceName = "Province Name" - GeoCodeStatus = "Geo Code Status" - ImageMediaId = "Business Icon" - AccountLocationAdExtension = "Account Location Ad Extension" - CampaignLocationAdExtension = "Campaign Location Ad Extension" - - # Call Ad Extensions - CountryCode = "Country Code" - IsCallOnly = "Call Only" - CampaignCallAdExtension = "Campaign Call Ad Extension" - IsCallTrackingEnabled = "Call Tracking Enabled" - RequireTollFreeTrackingNumber = "Toll Free" - - #Action Ad Extension - ActionAdExtension = "Action Ad Extension" - AccountActionAdExtension = "Account Action Ad Extension" - CampaignActionAdExtension = "Campaign Action Ad Extension" - AdGroupActionAdExtension = "Ad Group Action Ad Extension" - ActionType = "Action Type" - ActionText = "Action Text" - - # Structured Snippet Ad Extension - StructuredSnippetAdExtension = "Structured Snippet Ad Extension" - AccountStructuredSnippetAdExtension = "Account Structured Snippet Ad Extension" - CampaignStructuredSnippetAdExtension = "Campaign Structured Snippet Ad Extension" - AdGroupStructuredSnippetAdExtension = "Ad Group Structured Snippet Ad Extension" - StructuredSnippetHeader = "Structured Snippet Header" - StructuredSnippetValues = "Structured Snippet Values" - - # Sitelink Ad Extension - SitelinkAdExtension = "Sitelink Ad Extension" - AdGroupSitelinkAdExtension = "Ad Group Sitelink Ad Extension" - CampaignSitelinkAdExtension = "Campaign Sitelink Ad Extension" - AccountSitelinkAdExtension = "Account Sitelink Ad Extension" - - # Editorial Rejection Reasons - PublisherCountries = "Publisher Countries" - - # BTE Types - KeywordFirstPageBidType = "Keyword First Page Bid" - KeywordMainLineBidType = "Keyword Main Line Bid" - KeywordBestPositionBidType = "Keyword Best Position Bid" - - ProductCondition1 = "Product Condition 1" - ProductCondition2 = "Product Condition 2" - ProductCondition3 = "Product Condition 3" - ProductCondition4 = "Product Condition 4" - ProductCondition5 = "Product Condition 5" - ProductCondition6 = "Product Condition 6" - ProductCondition7 = "Product Condition 7" - ProductCondition8 = "Product Condition 8" - ProductValue1 = "Product Value 1" - ProductValue2 = "Product Value 2" - ProductValue3 = "Product Value 3" - ProductValue4 = "Product Value 4" - ProductValue5 = "Product Value 5" - ProductValue6 = "Product Value 6" - ProductValue7 = "Product Value 7" - ProductValue8 = "Product Value 8" - - BingMerchantCenterId = "Store Id" - BingMerchantCenterName = "Store Name" - - # App Ad Extension - AppAdExtension = "App Ad Extension" - AppPlatform = "App Platform" - AppStoreId = "App Id" - AccountAppAdExtension = "Account App Ad Extension" - CampaignAppAdExtension = "Campaign App Ad Extension" - AdGroupAppAdExtension = "Ad Group App Ad Extension" - IsTrackingEnabled = "Tracking Enabled" - - # Misc Stuff - EntityActiveStatus = "Active" - EntityDeletedStatus = "Deleted" - IntraFieldSeparator = ';' - Active = "Active" - Latitude = "Latitude" - Longitude = "Longitude" - - # BI - Spend = "Spend" - Impressions = "Impressions" - Clicks = "Clicks" - CTR = "CTR" - AvgCPC = "Avg CPC" - AvgCPM = "Avg CPM" - AvgPosition = "Avg position" - Conversions = "Conversions" - CPA = "CPA" - QualityScore = "Quality Score" - KeywordRelevance = "Keyword Relevance" - LandingPageRelevance = "Landing Page Relevance" - LandingPageUserExperience = "Landing Page User Experience" - - # DayTime Criterion - FromHour = "From Hour" - ToHour = "To Hour" - FromMinute = "From Minute" - ToMinute = "To Minute" - - # Shared Entities - NegativeKeywordList = "Negative Keyword List" - CampaignNegativeKeywordList = "Campaign Negative Keyword List Association" - ListNegativeKeyword = "Shared Negative Keyword" - - # Subtypes - MetroAreaSubType = "Metro Area" - CountrySubType = "Country" - StateSubType = "State" - CitySubType = "City" - PostalCodeSubType = "Postal Code" - - # Bing Shopping Campaigns - IsExcluded = "Is Excluded" - ParentAdGroupCriterionId = "Parent Criterion Id" - CampaignType = "Campaign Type" - CampaignPriority = "Priority" - LocalInventoryAdsEnabled = "LocalInventoryAdsEnabled" - - # CoOp - BidOption = "Bid Option" - BidBoostValue = "Bid Boost Value" - MaximumBid = "Maximum Bid" - - # V10 added - FieldPath = "Field Path" - - # Upgrade URL - FinalUrl = "Final Url" - FinalMobileUrl = "Mobile Final Url" - TrackingTemplate = "Tracking Template" - CustomParameter = "Custom Parameter" - - # Review Ad Extension - ReviewAdExtension = "Review Ad Extension" - AccountReviewAdExtension = "Account Review Ad Extension" - CampaignReviewAdExtension = "Campaign Review Ad Extension" - AdGroupReviewAdExtension = "Ad Group Review Ad Extension" - IsExact = "Is Exact" - Source = "Source" - Url = "Url" - - # Price Ad Extension - PriceAdExtension = "Price Ad Extension" - AccountPriceAdExtension = "Account Price Ad Extension" - CampaignPriceAdExtension = "Campaign Price Ad Extension" - AdGroupPriceAdExtension = "Ad Group Price Ad Extension" - PriceExtensionType = "Price Extension Type" - Header1 = "Header 1" - Header2 = "Header 2" - Header3 = "Header 3" - Header4 = "Header 4" - Header5 = "Header 5" - Header6 = "Header 6" - Header7 = "Header 7" - Header8 = "Header 8" - PriceDescription1 = "Price Description 1" - PriceDescription2 = "Price Description 2" - PriceDescription3 = "Price Description 3" - PriceDescription4 = "Price Description 4" - PriceDescription5 = "Price Description 5" - PriceDescription6 = "Price Description 6" - PriceDescription7 = "Price Description 7" - PriceDescription8 = "Price Description 8" - FinalUrl1 = "Final Url 1" - FinalUrl2 = "Final Url 2" - FinalUrl3 = "Final Url 3" - FinalUrl4 = "Final Url 4" - FinalUrl5 = "Final Url 5" - FinalUrl6 = "Final Url 6" - FinalUrl7 = "Final Url 7" - FinalUrl8 = "Final Url 8" - FinalMobileUrl1 = "Final Mobile Url 1" - FinalMobileUrl2 = "Final Mobile Url 2" - FinalMobileUrl3 = "Final Mobile Url 3" - FinalMobileUrl4 = "Final Mobile Url 4" - FinalMobileUrl5 = "Final Mobile Url 5" - FinalMobileUrl6 = "Final Mobile Url 6" - FinalMobileUrl7 = "Final Mobile Url 7" - FinalMobileUrl8 = "Final Mobile Url 8" - Price1 = "Price 1" - Price2 = "Price 2" - Price3 = "Price 3" - Price4 = "Price 4" - Price5 = "Price 5" - Price6 = "Price 6" - Price7 = "Price 7" - Price8 = "Price 8" - CurrencyCode1 = "Currency Code 1" - CurrencyCode2 = "Currency Code 2" - CurrencyCode3 = "Currency Code 3" - CurrencyCode4 = "Currency Code 4" - CurrencyCode5 = "Currency Code 5" - CurrencyCode6 = "Currency Code 6" - CurrencyCode7 = "Currency Code 7" - CurrencyCode8 = "Currency Code 8" - PriceUnit1 = "Price Unit 1" - PriceUnit2 = "Price Unit 2" - PriceUnit3 = "Price Unit 3" - PriceUnit4 = "Price Unit 4" - PriceUnit5 = "Price Unit 5" - PriceUnit6 = "Price Unit 6" - PriceUnit7 = "Price Unit 7" - PriceUnit8 = "Price Unit 8" - PriceQualifier1 = "Price Qualifier 1" - PriceQualifier2 = "Price Qualifier 2" - PriceQualifier3 = "Price Qualifier 3" - PriceQualifier4 = "Price Qualifier 4" - PriceQualifier5 = "Price Qualifier 5" - PriceQualifier6 = "Price Qualifier 6" - PriceQualifier7 = "Price Qualifier 7" - PriceQualifier8 = "Price Qualifier 8" - - # Callout Ad Extension - CalloutAdExtension = "Callout Ad Extension" - AccountCalloutAdExtension = "Account Callout Ad Extension" - CampaignCalloutAdExtension = "Campaign Callout Ad Extension" - AdGroupCalloutAdExtension = "Ad Group Callout Ad Extension" - CalloutText = "Callout Text" - - # Bid Strategy - BidStrategyType = "Bid Strategy Type" - BidStrategyMaxCpc = "Bid Strategy MaxCpc" - BidStrategyTargetCpa = "Bid Strategy TargetCpa" - InheritedBidStrategyType = "Inherited Bid Strategy Type" - - # Remarketing - Audience = "Audience" - Description = "Description" - MembershipDuration = "Membership Duration" - Scope = "Scope" - TagId = "UET Tag Id" - AudienceId = "Audience Id" - TargetSetting = "Target Setting" - RemarketingRule = "Remarketing Rule" - AudienceSearchSize = "Audience Search Size" - ProductAudience = "Product Audience" - AudienceNetworkSize = "Audience Network Size" - SupportedCampaignTypes = "Supported Campaign Types" - ProductAudienceType = "Product Audience Type" - SourceId = "Source Id" - ProductAudienceType = "Product Audience Type" - AdGroupProductAudienceAssociation = "Ad Group Product Audience Association" - AdGroupNegativeProductAudienceAssociation = "Ad Group Negative Product Audience Association" - CampaignProductAudienceAssociation = "Campaign Product Audience Association" - CampaignNegativeProductAudienceAssociation = "Campaign Negative Product Audience Association" - SimilarRemarketingList = "Similar Remarketing List" - AdGroupSimilarRemarketingListAssociation = "Ad Group Similar Remarketing List Association" - AdGroupNegativeSimilarRemarketingListAssociation = "Ad Group Negative Similar Remarketing List Association" - CampaignSimilarRemarketingListAssociation = "Campaign Similar Remarketing List Association" - CampaignNegativeSimilarRemarketingListAssociation = "Campaign Negative Similar Remarketing List Association" - RemarketingList = "Remarketing List" - AdGroupRemarketingListAssociation = 'Ad Group Remarketing List Association' - AdGroupNegativeRemarketingListAssociation = 'Ad Group Negative Remarketing List Association' - CampaignRemarketingListAssociation = 'Campaign Remarketing List Association' - CampaignNegativeRemarketingListAssociation = 'Campaign Negative Remarketing List Association' - CustomAudience = "Custom Audience"; - AdGroupCustomAudienceAssociation = "Ad Group Custom Audience Association" - AdGroupNegativeCustomAudienceAssociation = "Ad Group Negative Custom Audience Association" - CampaignCustomAudienceAssociation = "Campaign Custom Audience Association" - CampaignNegativeCustomAudienceAssociation = "Campaign Negative Custom Audience Association" - InMarketAudience = "In Market Audience" - AdGroupInMarketAudienceAssociation = "Ad Group In Market Audience Association" - AdGroupNegativeInMarketAudienceAssociation = "Ad Group Negative In Market Audience Association" - CampaignInMarketAudienceAssociation = "Campaign In Market Audience Association" - CampaignNegativeInMarketAudienceAssociation = "Campaign Negative In Market Audience Association" - # Expanded Text Ad - TitlePart1 = "Title Part 1" - TitlePart2 = "Title Part 2" - TitlePart3 = "Title Part 3" - Path1 = "Path 1" - Path2 = "Path 2" - Domain = "Domain" - - # Ad Extension Scheduling - AdSchedule = "Ad Schedule" - UseSearcherTimeZone = "Use Searcher Time Zone" - - # Dynamic Search Ads - DomainLanguage = "Domain Language" - DynamicAdTargetCondition1 = "Dynamic Ad Target Condition 1" - DynamicAdTargetValue1 = "Dynamic Ad Target Value 1" - DynamicAdTargetCondition2 = "Dynamic Ad Target Condition 2" - DynamicAdTargetValue2 = "Dynamic Ad Target Value 2" - DynamicAdTargetCondition3 = "Dynamic Ad Target Condition 3" - DynamicAdTargetValue3 = "Dynamic Ad Target Value 3" - - AdGroupAgeCriterion = "Ad Group Age Criterion" - AdGroupDayTimeCriterion = "Ad Group DayTime Criterion" - AdGroupDeviceCriterion = "Ad Group DeviceOS Criterion" - AdGroupGenderCriterion = "Ad Group Gender Criterion" - AdGroupRadiusCriterion = "Ad Group Radius Criterion" - AdGroupLocationCriterion = "Ad Group Location Criterion" - AdGroupLocationIntentCriterion = "Ad Group Location Intent Criterion" - AdGroupNegativeLocationCriterion = "Ad Group Negative Location Criterion" - AdGroupCompanyNameCriterion = "Ad Group Company Name Criterion" - AdGroupIndustryCriterion = "Ad Group Industry Criterion" - AdGroupJobFunctionCriterion = "Ad Group Job Function Criterion" - AdGroupNegativeAgeCriterion = "Ad Group Negative Age Criterion" - AdGroupNegativeCompanyNameCriterion = "Ad Group Negative Company Name Criterion" - AdGroupNegativeGenderCriterion = "Ad Group Negative Gender Criterion" - AdGroupNegativeIndustryCriterion = "Ad Group Negative Industry Criterion" - AdGroupNegativeJobFunctionCriterion = "Ad Group Negative Job Function Criterion" - - - # Responsive Ad - ResponsiveAd = "Responsive Ad" - CallToAction = "Call To Action" - Headline = "Headline" - Images = "Images" - LandscapeImageMediaId = "Landscape Image Media Id" - LandscapeLogoMediaId = "Landscape Logo Media Id" - LongHeadline = "Long Headline" - SquareImageMediaId = "Square Image Media Id" - SquareLogoMediaId = "Square Logo Media Id" - - # Responsive Search Ad - ResponsiveSearchAd = "Responsive Search Ad" - - # Labels - ColorCode = "Color" - Label = "Label" - CampaignLabel = "Campaign Label" - AdGroupLabel = "Ad Group Label" - KeywordLabel = "Keyword Label" - AppInstallAdLabel = "App Install Ad Label" - DynamicSearchAdLabel = "Dynamic Search Ad Label" - ExpandedTextAdLabel = "Expanded Text Ad Label" - ProductAdLabel = "Product Ad Label" - TextAdLabel = "Text Ad Label" - ResponsiveAdLabel = "Responsive Ad Label" - ResponsiveSearchAdLabel = "Responsive Search Ad Label" - - # Offline Conversions - OfflineConversion = "Offline Conversion" - ConversionCurrencyCode = "Conversion Currency Code" - ConversionName = "Conversion Name" - ConversionTime = "Conversion Time" - ConversionValue = "Conversion Value" - MicrosoftClickId = "Microsoft Click Id" - - # Campaign Criterion - CampaignAgeCriterion = 'Campaign Age Criterion' - CampaignDayTimeCriterion = 'Campaign DayTime Criterion' - CampaignDeviceOSCriterion = 'Campaign DeviceOS Criterion' - CampaignGenderCriterion = 'Campaign Gender Criterion' - CampaignLocationCriterion = 'Campaign Location Criterion' - CampaignLocationIntentCriterion = 'Campaign Location Intent Criterion' - CampaignNegativeLocationCriterion = 'Campaign Negative Location Criterion' - CampaignRadiusCriterion = 'Campaign Radius Criterion' - CampaignCompanyNameCriterion = 'Campaign Company Name Criterion' - CampaignJobFunctionCriterion = 'Campaign Job Function Criterion' - CampaignIndustryCriterion = 'Campaign Industry Criterion' - - FinalUrlSuffix = "Final Url Suffix" diff --git a/bingads/v12/internal/extensions.py b/bingads/v12/internal/extensions.py deleted file mode 100644 index 4bd8bb1d..00000000 --- a/bingads/v12/internal/extensions.py +++ /dev/null @@ -1,1423 +0,0 @@ -from datetime import datetime - -from bingads.v12.internal.bulk.string_table import _StringTable -from six import PY2 -import re -import json -from bingads.service_client import _CAMPAIGN_OBJECT_FACTORY_V12, _CAMPAIGN_MANAGEMENT_SERVICE_V12 - -target_setting_detail_pattern="^(Age|Audience|CompanyName|Gender|Industry|JobFunction)$" - -DELETE_VALUE = "delete_value" -_BULK_DATETIME_FORMAT = '%m/%d/%Y %H:%M:%S' -_BULK_DATETIME_FORMAT_2 = '%m/%d/%Y %H:%M:%S.%f' -_BULK_DATE_FORMAT = "%m/%d/%Y" - -url_splitter = ";\\s*(?=https?://)" -custom_param_splitter = "(? 0: - return DELETE_VALUE - return value - - -def csv_to_status(c, v): - if v == 'Expired': - c.ad_group.Status = 'Expired' - c._is_expired = True - else: - c.ad_group.Status = v if v else None - - -def bulk_device_preference_str(value): - if value is None: - return None - elif value == 0: - return "All" - elif value == 30001: - return "Mobile" - else: - raise ValueError("Unknown device preference") - - -def parse_datetime(dt_str): - """ Convert the datetime str to datetime object. - - :param dt_str: The string representing a datetime object. - :type dt_str: str - :return: The datetime object parsed from the string. - :rtype: datetime | None - """ - - if not dt_str: - return None - try: - return datetime.strptime(dt_str, _BULK_DATETIME_FORMAT) - except Exception: - return datetime.strptime(dt_str, _BULK_DATETIME_FORMAT_2) - - -def parse_date(d_str): - if not d_str: - return None - parsed_date = datetime.strptime(d_str, _BULK_DATE_FORMAT) - bing_ads_date = _CAMPAIGN_OBJECT_FACTORY_V12.create('Date') - bing_ads_date.Day = parsed_date.day - bing_ads_date.Month = parsed_date.month - bing_ads_date.Year = parsed_date.year - - return bing_ads_date - - -def parse_device_preference(value): - if not value: - return None - - if value.lower() == 'all': - return 0 - elif value.lower() == "mobile": - return 30001 - else: - raise ValueError("Unknown device preference") - -def field_to_csv_MediaIds(entity): - """ - MediaIds field to csv content - :param entity: entity which has MediaIds attribute - :return: - """ - # media_ids? "ns4:ArrayOflong" - media_ids = entity.ImageMediaIds - if media_ids is None or len(media_ids) == 0: - return None - return ';'.join(str(media_id) for media_id in media_ids) - - -def csv_to_field_MediaIds(entity, value): - """ - MediaIds csv to entity - :param entity: - :return: - """ - entity.ImageMediaIds = [None if i == 'None' else int(i) for i in value.split(';')] - - -# None and empty string will set to empty string -def escape_parameter_text(s): - return '' if not s else s.replace('\\', '\\\\').replace(';', '\\;') - - -def unescape_parameter_text(s): - return '' if not s else s.replace('\\\\', '\\').replace('\\;', ';') - - -def field_to_csv_UrlCustomParameters(entity): - """ - transfer the CustomParameters of a entity to csv content (string) - :param entity: the entity which contains UrlCustomparameters attribute - :return: csv string content - """ - if entity is None or entity.UrlCustomParameters is None: - return None - if entity.UrlCustomParameters.Parameters is None or entity.UrlCustomParameters.Parameters.CustomParameter is None: - return DELETE_VALUE if entity.Id and entity.Id > 0 else None - # The default case when entity created - if len(entity.UrlCustomParameters.Parameters.CustomParameter) == 0: - return None - params = [] - for parameter in entity.UrlCustomParameters.Parameters.CustomParameter: - params.append('{{_{0}}}={1}'.format(parameter.Key, escape_parameter_text(parameter.Value))) - return '; '.join(params) - - -def csv_to_field_UrlCustomParameters(entity, value): - if value is None or value.strip() == '': - return - splitter = re.compile(custom_param_splitter) - pattern = re.compile(custom_param_pattern) - params = [] - param_strs = splitter.split(value) - for param_str in param_strs: - match = pattern.match(param_str) - if match: - custom_parameter = _CAMPAIGN_OBJECT_FACTORY_V12.create("CustomParameter") - custom_parameter.Key = match.group(1) - custom_parameter.Value = unescape_parameter_text(match.group(2)) - params.append(custom_parameter) - if len(params) > 0: - entity.UrlCustomParameters.Parameters.CustomParameter = params - - -def csv_to_field_Urls(entity, value): - """ - set FinalUrls / FinalMobileUrls string field - :param entity: FinalUrls / FinalMobileUrls - :param value: the content in csv - :return:set field values - """ - if value is None or value == '': - return - splitter = re.compile(url_splitter) - entity.string = splitter.split(value) - - -def field_to_csv_Urls(entity, id): - """ - parse entity to csv content - :param entity: FinalUrls / FinalMobileUrls - :return: csv content - """ - if entity is None: - return None - if entity.string is None: - return DELETE_VALUE if id and id > 0 else None - if len(entity.string) == 0: - 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 or entity.string is None: - return None - if len(entity.string) == 0: - return None - return ';'.join(entity.string) - -def field_to_csv_BidStrategyType(entity): - """ - parse entity to csv content - :param entity: entity which has BiddingScheme attribute - :return: csv content - """ - if entity.BiddingScheme is None or type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('BiddingScheme')): - return None - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('EnhancedCpcBiddingScheme')): - return 'EnhancedCpc' - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('InheritFromParentBiddingScheme')): - return 'InheritFromParent' - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('MaxConversionsBiddingScheme')): - return 'MaxConversions' - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('ManualCpcBiddingScheme')): - return 'ManualCpc' - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('TargetCpaBiddingScheme')): - return 'TargetCpa' - elif type(entity.BiddingScheme) == type(_CAMPAIGN_OBJECT_FACTORY_V12.create('MaxClicksBiddingScheme')): - return 'MaxClicks' - else: - raise TypeError('Unsupported Bid Strategy Type') - - -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_V12.create('EnhancedCpcBiddingScheme') - elif value == 'InheritFromParent': - entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V12.create('InheritFromParentBiddingScheme') - elif value == 'MaxConversions': - entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V12.create('MaxConversionsBiddingScheme') - elif value == 'ManualCpc': - entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V12.create('ManualCpcBiddingScheme') - elif value == 'TargetCpa': - entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V12.create('TargetCpaBiddingScheme') - elif value == 'MaxClicks': - entity.BiddingScheme = _CAMPAIGN_OBJECT_FACTORY_V12.create('MaxClicksBiddingScheme') - else: - raise ValueError('Unknown Bid Strategy Type') - entity.BiddingScheme.Type = value - - -def csv_to_field_StructuredSnippetValues(entity, value): - if value is not None and value != '': - entity.Values.string = value.split(';') - -def field_to_csv_StructuredSnippetValues(entity): - if entity.Values is not None and entity.Values.string is not None and len(entity.Values.string) > 0: - return ';'.join(entity.Values.string) - return None - - -def csv_to_field_Rsa_TextAssetLinks(assetLinks, value): - if value is None or value == '': - return - assetLinkContracts = json.loads(value) - - for assetLinkContract in assetLinkContracts: - asset_link = _CAMPAIGN_OBJECT_FACTORY_V12.create('AssetLink') - asset_link.Asset = _CAMPAIGN_OBJECT_FACTORY_V12.create('TextAsset') - asset_link.Asset.Type = 'TextAsset' - asset_link.Asset.Id = assetLinkContract['id'] if 'id' in assetLinkContract else None - asset_link.Asset.Text = assetLinkContract['text'] if 'text' in assetLinkContract else None - asset_link.Asset.Name = assetLinkContract['name'] if 'name' in assetLinkContract else None - asset_link.AssetPerformanceLabel = assetLinkContract['assetPerformanceLabel'] if 'assetPerformanceLabel' in assetLinkContract else None - asset_link.PinnedField = assetLinkContract['pinnedField'] if 'pinnedField' in assetLinkContract else None - asset_link.EditorialStatus = assetLinkContract['editorialStatus'] if 'editorialStatus' in assetLinkContract else None - assetLinks.AssetLink.append(asset_link) - -def field_to_csv_ImageAssetLinks(entity): - if entity is None or entity.AssetLink is None: - return None - assetLinkContracts = [] - for assetLink in entity.AssetLink: - if assetLink.Asset is not None and isinstance(assetLink.Asset, ImageAsset_Type): - contract = {} - contract['cropHeight'] = assetLink.Asset.CropHeight if hasattr(assetLink.Asset, 'CropHeight') else None - contract['cropWidth'] = assetLink.Asset.CropWidth if hasattr(assetLink.Asset, 'CropWidth') else None - contract['cropX'] = assetLink.Asset.CropX if hasattr(assetLink.Asset, 'CropX') else None - contract['cropY'] = assetLink.Asset.CropY if hasattr(assetLink.Asset, 'CropY') else None - contract['id'] = assetLink.Asset.Id if hasattr(assetLink.Asset, 'Id') else None - contract['name'] = assetLink.Asset.Name if hasattr(assetLink.Asset, 'Name') else None - contract['assetPerformanceLabel'] = assetLink.AssetPerformanceLabel if hasattr(assetLink, 'AssetPerformanceLabel') else None - contract['editorialStatus'] = assetLink.EditorialStatus if hasattr(assetLink, 'EditorialStatus') else None - contract['pinnedField'] = assetLink.PinnedField if hasattr(assetLink, 'PinnedField') else None - assetLinkContracts.append(contract) - if len(assetLinkContracts) > 0: - return json.dumps(assetLinkContracts) - return None - -def csv_to_field_ImageAssetLinks(assetLinks, value): - if value is None or value == '': - return - assetLinkContracts = json.loads(value) - - for assetLinkContract in assetLinkContracts: - asset_link = _CAMPAIGN_OBJECT_FACTORY_V12.create('AssetLink') - asset_link.Asset = _CAMPAIGN_OBJECT_FACTORY_V12.create('ImageAsset') - asset_link.Asset.Type = 'ImageAsset' - asset_link.Asset.CropHeight = assetLinkContract['cropHeight'] if 'cropHeight' in assetLinkContract else None - asset_link.Asset.CropWidth = assetLinkContract['cropWidth'] if 'cropWidth' in assetLinkContract else None - asset_link.Asset.CropX = assetLinkContract['cropX'] if 'cropX' in assetLinkContract else None - asset_link.Asset.CropY = assetLinkContract['cropY'] if 'cropY' in assetLinkContract else None - asset_link.Asset.Id = assetLinkContract['id'] if 'id' in assetLinkContract else None - asset_link.Asset.Name = assetLinkContract['name'] if 'name' in assetLinkContract else None - asset_link.AssetPerformanceLabel = assetLinkContract['assetPerformanceLabel'] if 'assetPerformanceLabel' in assetLinkContract else None - asset_link.PinnedField = assetLinkContract['pinnedField'] if 'pinnedField' in assetLinkContract else None - asset_link.EditorialStatus = assetLinkContract['editorialStatus'] if 'editorialStatus' in assetLinkContract else None - assetLinks.AssetLink.append(asset_link) - -def field_to_csv_Rsa_TextAssetLinks(entity): - if entity is None or entity.AssetLink is None: - return None - assetLinkContracts = [] - for assetLink in entity.AssetLink: - if assetLink.Asset is not None and isinstance(assetLink.Asset, TextAsset_Type): - contract = {} - contract['id'] = assetLink.Asset.Id if hasattr(assetLink.Asset, 'Id') else None - contract['name'] = assetLink.Asset.Name if hasattr(assetLink.Asset, 'Name') else None - contract['text'] = assetLink.Asset.Text if hasattr(assetLink.Asset, 'Text') else None - contract['assetPerformanceLabel'] = assetLink.AssetPerformanceLabel if hasattr(assetLink, 'AssetPerformanceLabel') else None - contract['editorialStatus'] = assetLink.EditorialStatus if hasattr(assetLink, 'EditorialStatus') else None - contract['pinnedField'] = assetLink.PinnedField if hasattr(assetLink, 'PinnedField') else None - assetLinkContracts.append(contract) - if len(assetLinkContracts) > 0: - return json.dumps(assetLinkContracts) - return None - - -def ad_rotation_bulk_str(value, id): - if value is None: - return None - elif value.Type is None: - return DELETE_VALUE if id and id > 0 else None - else: - return bulk_str(value.Type) - - -def parse_ad_rotation(value): - if not value: - return None - ad_rotation = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdRotation') - ad_rotation.Type = None if value == DELETE_VALUE else value - return ad_rotation - - -def parse_ad_group_bid(value): - if not value: - return None - bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('Bid') - bid.Amount = float(value) - return bid - - -def ad_group_bid_bulk_str(value): - if value is None or value.Amount is None: - return None - return bulk_str(value.Amount) - - -def keyword_bid_bulk_str(value, id): - if value is None: - return DELETE_VALUE if id and id > 0 else None - if value.Amount is None: - return None - return bulk_str(value.Amount) - - -def parse_keyword_bid(value): - bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('Bid') - if not value or value == DELETE_VALUE: - bid.Amount = None - else: - bid.Amount = float(value) - return bid - - -def bid_bulk_str(value, id): - if value is None: - return DELETE_VALUE if id and id > 0 else None - if value.Amount is None: - return None - return bulk_str(value.Amount) - - -def parse_bid(value): - bid = _CAMPAIGN_OBJECT_FACTORY_V12.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' - elif value == 'Fifteen': - return '15' - elif value == 'Thirty': - return '30' - elif value == 'FortyFive': - return '45' - else: - raise ValueError('Unknown minute') - -def parse_fixed_bid(value): - if not value: - return None - fixed_bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('FixedBid') - fixed_bid.Amount = float(value) - return fixed_bid - -def fixed_bid_bulk_str(value): - if value is None or not hasattr(value, 'Amount') or value.Amount is None: - return None - return bulk_str(value.Amount) - -def bid_multiplier_bulk_str(value): - if value is None or not hasattr(value, 'Multiplier') or value.Multiplier is None: - return None - return bulk_str(value.Multiplier) - -def parse_minute(value): - minute_number = int(value) - if minute_number == 0: - return 'Zero' - elif minute_number == 15: - return 'Fifteen' - elif minute_number == 30: - return 'Thirty' - elif minute_number == 45: - return 'FortyFive' - raise ValueError('Unknown minute') - - -def format_Day(value): - Day = _CAMPAIGN_OBJECT_FACTORY_V12.create('Day') - if value.lower() == 'monday': - return Day.Monday - elif value.lower() == 'tuesday': - return Day.Tuesday - elif value.lower() == 'wednesday': - return Day.Wednesday - elif value.lower() == 'thursday': - return Day.Thursday - elif value.lower() == 'friday': - return Day.Friday - elif value.lower() == 'saturday': - return Day.Saturday - elif value.lower() == 'sunday': - return Day.Sunday - raise ValueError('Unable to parse day: {0}'.format(value)) - -def parse_location_target_type(value): - if value == 'Metro Area': - return 'MetroArea' - elif value == 'Postal Code': - return 'PostalCode' - else: - return value - - -def location_target_type_bulk_str(value): - if value == 'MetroArea': - return 'Metro Area' - elif value == 'PostalCode': - return 'Postal Code' - else: - return value - - -def field_to_csv_AdSchedule(entity, id): - """ - get the bulk string for Scheduling DayTimeRanges - :param entity: Scheduling entity - :return: bulk str - """ - if entity is None: - return None - if entity.DayTimeRanges is None: - return DELETE_VALUE if id and id > 0 else None - return ';'.join('({0}[{1:02d}:{2:02d}-{3:02d}:{4:02d}])' - .format(d.Day, d.StartHour, int(minute_bulk_str(d.StartMinute)), d.EndHour, int(minute_bulk_str(d.EndMinute))) - for d in entity.DayTimeRanges.DayTime - ) - - -def csv_to_field_AdSchedule(entity, value): - if value is None or value.strip() == '': - return - daytime_strs = value.split(';') - ad_schedule_pattern = '\((Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\[(\d\d?):(\d\d)-(\d\d?):(\d\d)\]\)' - pattern = re.compile(ad_schedule_pattern, re.IGNORECASE) - daytimes = [] - for daytime_str in daytime_strs: - match = pattern.match(daytime_str) - if match: - daytime = _CAMPAIGN_OBJECT_FACTORY_V12.create('DayTime') - daytime.Day = format_Day(match.group(1)) - daytime.StartHour = int(match.group(2)) - daytime.StartMinute = parse_minute(match.group(3)) - daytime.EndHour = int(match.group(4)) - daytime.EndMinute = parse_minute(match.group(5)) - daytimes.append(daytime) - else: - raise ValueError('Unable to parse DayTime: {0}'.format(daytime_str)) - entity.DayTimeRanges.DayTime = daytimes - - -def field_to_csv_SchedulingStartDate(entity, id): - """ - write scheduling StartDate to bulk string - :param entity: Scheduling entity - :return: date bulk string - """ - if entity is None: - return None - elif entity.StartDate is None: - return DELETE_VALUE if id and id > 0 else None - # this case is what the suds creates by default. return None instead of a delete value - elif entity.StartDate.Day is None and entity.StartDate.Month is None and entity.StartDate.Year is None: - return None - return '{0!s}/{1!s}/{2!s}'.format(entity.StartDate.Month, entity.StartDate.Day, entity.StartDate.Year) - - -def field_to_csv_SchedulingEndDate(entity, id): - """ - write scheduling EndDate to bulk string - :param entity: Scheduling entity - :return: date bulk string - """ - if entity is None: - return None - elif entity.EndDate is None: - return DELETE_VALUE if id and id > 0 else None - # this case is what the suds creates by default. return None instead of a delete value - elif entity.EndDate.Day is None and entity.EndDate.Month is None and entity.EndDate.Year is None: - return None - return '{0!s}/{1!s}/{2!s}'.format(entity.EndDate.Month, entity.EndDate.Day, entity.EndDate.Year) - - -def field_to_csv_UseSearcherTimeZone(entity, id): - """ - get Scheduling UseSearcherTimeZone bulk str - :param entity: Scheduling entity - :return: bulk str - """ - if entity is None: - return None - # this case is what suds creates by default, while set it to delete value since there's no other case for delete value - elif entity.UseSearcherTimeZone is None: - return DELETE_VALUE if id and id > 0 else None - else: - return str(entity.UseSearcherTimeZone) - - -def csv_to_field_BudgetType(entity, value, version=12): - if value is None or value == '': - entity.BudgetType = None - elif value == 'MonthlyBudgetSpendUntilDepleted' and version == 12: - entity.BudgetType = BudgetLimitType.MonthlyBudgetSpendUntilDepleted - elif value == 'DailyBudgetAccelerated': - entity.BudgetType = BudgetLimitType.DailyBudgetAccelerated - elif value == 'DailyBudgetStandard': - entity.BudgetType = BudgetLimitType.DailyBudgetStandard - else: - raise ValueError('Unable to parse BudgetType: {0}'.format(value)) - -def field_to_csv_WebpageParameter_CriterionName(entity): - if entity.Criterion is None or entity.Criterion.Parameter is None or entity.Criterion.Parameter.CriterionName is None: - return None - if not entity.Criterion.Parameter.CriterionName: - return DELETE_VALUE if entity.Id and entity.Id > 0 else None - return entity.Criterion.Parameter.CriterionName - - -def csv_to_field_WebpageParameter_CriterionName(entity, value): - if value is None or value == '': - return - if entity.Criterion is not None and isinstance(entity.Criterion, type(Webpage)): - entity.Criterion.Parameter.CriterionName = value - else: - webpage = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage') - webpage.Parameter.CriterionName = value - entity.Criterion = webpage - - -def entity_to_csv_DSAWebpageParameter(entity, row_values): - """ - Set Campaign/AdGroup Criterion (WebpagePage) Web page parameters from bulk values - :param entity: campaign/ad group criterion entity - :param row_values: bulk row values - """ - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion, type(Webpage)) and \ - entity.Criterion.Parameter is not None and entity.Criterion.Parameter.Conditions is not None and \ - entity.Criterion.Parameter.Conditions.WebpageCondition is not None: - condition_prefix = _StringTable.DynamicAdTargetCondition1[:-1] - value_prefix = _StringTable.DynamicAdTargetValue1[:-1] - - conditions = entity.Criterion.Parameter.Conditions.WebpageCondition - for i in range(0, len(conditions)): - row_values[condition_prefix + str(i + 1)] = conditions[i].Operand - row_values[value_prefix + str(i + 1)] = conditions[i].Argument - - -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_V12.create('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 - elif webpage_condition.lower() == 'customlabel': - condition.Operand = WebpageConditionOperand.CustomLabel - elif webpage_condition.lower() == 'unknown': - condition.Operand = WebpageConditionOperand.Unknown - 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) - - if len(conditions) > 0: - if entity.Criterion is not None and isinstance(entity.Criterion, type(Webpage)): - entity.Criterion.Parameter.Conditions.WebpageCondition = conditions - else: - webpage = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage') - webpage.Parameter.Conditions.WebpageCondition = conditions - entity.Criterion = webpage - -def entity_to_csv_PriceTableRows(entity, row_values): - """ - Set Price Ad Extension price table rows from bulk values - :param entity: price ad extension entity - :param row_values: bulk row values - """ - if entity is not None and entity.TableRows is not None and \ - entity.TableRows.PriceTableRow is not None: - currency_code_prefix = _StringTable.CurrencyCode1[:-1] - price_description_prefix = _StringTable.PriceDescription1[:-1] - header_prefix = _StringTable.Header1[:-1] - final_mobile_url_prefix = _StringTable.FinalMobileUrl1[:-1] - final_url_prefix = _StringTable.FinalUrl1[:-1] - price_prefix = _StringTable.Price1[:-1] - price_qualifier_prefix = _StringTable.PriceQualifier1[:-1] - price_unit_prefix = _StringTable.PriceUnit1[:-1] - - price_table_rows = entity.TableRows.PriceTableRow - for i in range(0, len(price_table_rows)): - row_values[currency_code_prefix + str(i + 1)] = price_table_rows[i].CurrencyCode - row_values[price_description_prefix + str(i + 1)] = price_table_rows[i].Description - row_values[header_prefix + str(i + 1)] = price_table_rows[i].Header - row_values[final_mobile_url_prefix + str(i + 1)] = field_to_csv_Urls(price_table_rows[i].FinalMobileUrls, entity.Id) - row_values[final_url_prefix + str(i + 1)] = field_to_csv_Urls(price_table_rows[i].FinalUrls, entity.Id) - row_values[price_prefix + str(i + 1)] = bulk_str(price_table_rows[i].Price) - row_values[price_qualifier_prefix + str(i + 1)] = price_table_rows[i].PriceQualifier - row_values[price_unit_prefix + str(i + 1)] = price_table_rows[i].PriceUnit - - -def csv_to_entity_PriceTableRows(row_values, entity): - """ - convert Price Ad Extension price table rows to bulk row values - :param row_values: bulk row values - :param entity: price ad extension entity - """ - MAX_NUMBER_OF_PRICE_TABLE_ROWS = 8 - currency_code_prefix = _StringTable.CurrencyCode1[:-1] - price_description_prefix = _StringTable.PriceDescription1[:-1] - header_prefix = _StringTable.Header1[:-1] - final_mobile_url_prefix = _StringTable.FinalMobileUrl1[:-1] - final_url_prefix = _StringTable.FinalUrl1[:-1] - price_prefix = _StringTable.Price1[:-1] - price_qualifier_prefix = _StringTable.PriceQualifier1[:-1] - price_unit_prefix = _StringTable.PriceUnit1[:-1] - - price_table_rows = [] - for i in range(0, MAX_NUMBER_OF_PRICE_TABLE_ROWS): - currency_code_success, currency_code = row_values.try_get_value(currency_code_prefix + str(i + 1)) - price_description_success, price_description = row_values.try_get_value(price_description_prefix + str(i + 1)) - header_success, header = row_values.try_get_value(header_prefix + str(i + 1)) - final_mobile_url_success, final_mobile_url = row_values.try_get_value(final_mobile_url_prefix + str(i + 1)) - final_url_success, final_url = row_values.try_get_value(final_url_prefix + str(i + 1)) - price_success, price = row_values.try_get_value(price_prefix + str(i + 1)) - price_qualifier_success, price_qualifier = row_values.try_get_value(price_qualifier_prefix + str(i + 1)) - price_unit_success, price_unit = row_values.try_get_value(price_unit_prefix + str(i + 1)) - - if currency_code_success \ - or price_description_success \ - or header_success \ - or final_mobile_url_success \ - or final_url_success \ - or price_success \ - or price_qualifier_success \ - or price_unit_success: - price_table_row = _CAMPAIGN_OBJECT_FACTORY_V12.create('PriceTableRow') - price_table_row.CurrencyCode = currency_code - price_table_row.Description = price_description - price_table_row.Header = header - csv_to_field_Urls(price_table_row.FinalMobileUrls, final_mobile_url) - csv_to_field_Urls(price_table_row.FinalUrls, final_url) - price_table_row.Price = price - price_table_row.PriceQualifier = price_qualifier - price_table_row.PriceUnit = price_unit - - price_table_rows.append(price_table_row) - - if len(price_table_rows) > 0: - entity.TableRows.PriceTableRow = price_table_rows - - -def parse_bool(value): - if value is None or value == '': - return None - elif value.lower() == 'true': - return True - elif value.lower() == 'false': - return False - else: - raise ValueError('Unable to parse bool value: {0}.'.format(value)) - - -def field_to_csv_RemarketingRule(entity): - """ - convert remarketing rule to bulk string - :param entity: remarketing list entity - """ - if entity.Rule == None: - return None - - rule = entity.Rule - if (isinstance(rule, type(PageVisitorsRule))): - return 'PageVisitors{0}'.format(rule_item_groups_str(rule.RuleItemGroups.RuleItemGroup)) - elif (isinstance(rule, type(PageVisitorsWhoVisitedAnotherPageRule))): - return 'PageVisitorsWhoVisitedAnotherPage({0}) and ({1})'.format( - rule_item_groups_str(rule.RuleItemGroups.RuleItemGroup), - rule_item_groups_str(rule.AnotherRuleItemGroups.RuleItemGroup)) - elif (isinstance(rule, type(PageVisitorsWhoDidNotVisitAnotherPageRule))): - return 'PageVisitorsWhoDidNotVisitAnotherPage({0}) and not ({1})'.format( - rule_item_groups_str(rule.IncludeRuleItemGroups.RuleItemGroup), - rule_item_groups_str(rule.ExcludeRuleItemGroups.RuleItemGroup)) - elif (isinstance(rule, type(CustomEventsRule))): - return 'CustomEvents{0}'.format(custom_event_rule_str(rule)) - elif (isinstance(rule, type(RemarketingRule))): - return None - else: - raise ValueError('Unsupported Remarketing Rule type: {0}'.format(type(entity.RemarketingRule))) - - -def rule_item_groups_str(groups): - if groups is None or len(groups) == 0: - raise ValueError('Remarketing RuleItemGroups is None or empty.') - - return ' or '.join(['({0})'.format(rule_items_str(group.Items.RuleItem)) for group in groups]) - - -def rule_items_str(items): - if items is None or len(items) == 0: - raise ValueError('Remarketing RuleItem list is None or empty.') - - return ' and '.join(['({0} {1} {2})'.format(item.Operand, item.Operator, item.Value) for item in items]) - - -def custom_event_rule_str(rule): - rule_items = [] - if rule.ActionOperator is not None and rule.Action is not None: - rule_items.append('Action {0} {1}'.format(rule.ActionOperator, rule.Action)) - if rule.CategoryOperator is not None and rule.Category is not None: - rule_items.append('Category {0} {1}'.format(rule.CategoryOperator, rule.Category)) - if rule.LabelOperator is not None and rule.Label is not None: - rule_items.append('Label {0} {1}'.format(rule.LabelOperator, rule.Label)) - if rule.ValueOperator is not None and rule.Value is not None: - rule_items.append('Value {0} {1}'.format(rule.ValueOperator, rule.Value)) - - if len(rule_items) == 0: - raise ValueError('Remarketing CustomEvents RuleItem list is empty') - - return ' and '.join('({0})'.format(item) for item in rule_items) - - -def csv_to_field_RemarketingRule(entity, value): - """ - parse remarketing rule string and set remarketing rule attribute value - :param entity: remarketing list entity - :param value: bulk string value - """ - if value is None or value == '': - return - - type_end_pos = value.index('(') - if type_end_pos <= 0: - raise ValueError('Invalid Remarketing Rule: {0}'.format(value)) - - rule_type = value[:type_end_pos] - rule = value[type_end_pos:] - - if rule_type.lower() == 'pagevisitors': - entity.Rule = parse_rule_PageVisitors(rule) - elif rule_type.lower() == 'pagevisitorswhovisitedanotherpage': - entity.Rule = parse_rule_PageVisitorsWhoVisitedAnotherPage(rule) - elif rule_type.lower() == 'pagevisitorswhodidnotvisitanotherpage': - entity.Rule = parse_rule_PageVisitorsWhoDidNotVisitAnotherPage(rule) - elif rule_type.lower() == 'customevents': - entity.Rule = parse_rule_CustomEvents(rule) - else: - raise ValueError('Invalid Remarketing Rule Type: {0}'.format(rule_type)) - - -def field_to_csv_CriterionAudienceId(entity): - if entity is None or entity.Criterion is None or entity.Criterion.AudienceId is None: - return None - return bulk_str(entity.Criterion.AudienceId) - - -def csv_to_field_CriterionAudienceId(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion, type(AudienceCriterion)): - entity.Criterion.AudienceId = value - - -def field_to_csv_BidAdjustment(entity): - if entity is None or entity.CriterionBid is None or entity.CriterionBid.Multiplier is None: - return None - return bulk_str(entity.CriterionBid.Multiplier) - - -def csv_to_field_BidAdjustment(entity, value): - if value is None or value == '': - return - if entity is not None and entity.CriterionBid is not None and isinstance(entity.CriterionBid, type(BidMultiplier)): - entity.CriterionBid.Multiplier = value - -def field_to_csv_AgeTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.AgeRange is None: - return None - return entity.Criterion.AgeRange - -def csv_to_field_AgeTarget(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(AgeCriterion)): - setattr(entity.Criterion, "AgeRange", value) - -def field_to_csv_DayTimeTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.Day is None: - return None - return entity.Criterion.Day - -def csv_to_field_DayTimeTarget(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DayTimeCriterion)): - setattr(entity.Criterion, "Day", value) - -def field_to_csv_FromHour(entity): - if entity is None or entity.Criterion is None or entity.Criterion.FromHour is None: - return None - return str(entity.Criterion.FromHour) - -def csv_to_field_FromHour(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DayTimeCriterion)): - setattr(entity.Criterion, "FromHour", value) - -def field_to_csv_FromMinute(entity): - if entity is None or entity.Criterion is None or entity.Criterion.FromMinute is None: - return None - return minute_bulk_str(entity.Criterion.FromMinute) - -def csv_to_field_FromMinute(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DayTimeCriterion)): - setattr(entity.Criterion, "FromMinute", parse_minute(value)) - -def field_to_csv_ToHour(entity): - if entity is None or entity.Criterion is None or entity.Criterion.ToHour is None: - return None - return str(entity.Criterion.ToHour) - -def csv_to_field_ToHour(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DayTimeCriterion)): - setattr(entity.Criterion, "ToHour", value) - -def field_to_csv_ToMinute(entity): - if entity is None or entity.Criterion is None or entity.Criterion.ToMinute is None: - return None - return minute_bulk_str(entity.Criterion.ToMinute) - -def csv_to_field_ToMinute(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DayTimeCriterion)): - setattr(entity.Criterion, "ToMinute", parse_minute(value)) - -def field_to_csv_DeviceTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.DeviceName is None: - return None - return entity.Criterion.DeviceName - -def csv_to_field_DeviceTarget(entity, value): - if value is None: - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DeviceCriterion)): - setattr(entity.Criterion, "DeviceName", value) - -def field_to_csv_OSName(entity): - if entity is None or entity.Criterion is None or entity.Criterion.OSName is None: - return None - return entity.Criterion.OSName - -def csv_to_field_OSName(entity, value): - if value is None: - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(DeviceCriterion)): - setattr(entity.Criterion, "OSName", value) - -def field_to_csv_GenderTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.GenderType is None: - return None - return entity.Criterion.GenderType - -def csv_to_field_GenderTarget(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(GenderCriterion)): - setattr(entity.Criterion, "GenderType", value) - -def field_to_csv_LocationTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.LocationId is None: - return None - return str(entity.Criterion.LocationId) - -def csv_to_field_LocationTarget(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(LocationCriterion)): - setattr(entity.Criterion, "LocationId", value) - -def field_to_csv_LocationType(entity): - if entity is None or entity.Criterion is None or entity.Criterion.LocationType is None: - return None - return entity.Criterion.LocationType - -def csv_to_field_LocationType(entity, value): - if value is None: - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(LocationCriterion)): - setattr(entity.Criterion, "LocationType", value) - -def field_to_csv_LocationName(entity): - if entity is None or entity.Criterion is None or entity.Criterion.DisplayName is None: - return None - return entity.Criterion.DisplayName - -def csv_to_field_LocationName(entity, value): - if value is None: - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(LocationCriterion)): - setattr(entity.Criterion, "DisplayName", value) - -def field_to_csv_LocationIntentTarget(entity): - if entity is None or entity.Criterion is None or entity.Criterion.IntentOption is None: - return None - return entity.Criterion.IntentOption - -def csv_to_field_LocationIntentTarget(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(LocationIntentCriterion)): - setattr(entity.Criterion, "IntentOption", value) - -def field_to_csv_RadiusName(entity): - if entity is None or entity.Criterion is None or entity.Criterion.Name is None: - return None - return entity.Criterion.Name - -def csv_to_field_RadiusName(entity, value): - if value is None: - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(RadiusCriterion)): - setattr(entity.Criterion, "Name", value) - -def field_to_csv_Radius(entity): - if entity is None or entity.Criterion is None or entity.Criterion.Radius is None: - return None - return str(entity.Criterion.Radius) - -def csv_to_field_Radius(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(RadiusCriterion)): - setattr(entity.Criterion, "Radius", value) - -def field_to_csv_RadiusUnit(entity): - if entity is None or entity.Criterion is None or entity.Criterion.RadiusUnit is None: - return None - return entity.Criterion.RadiusUnit - -def csv_to_field_RadiusUnit(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(RadiusCriterion)): - setattr(entity.Criterion, "RadiusUnit", value) - -def field_to_csv_LatitudeDegrees(entity): - if entity is None or entity.Criterion is None or entity.Criterion.LatitudeDegrees is None: - return None - return str(entity.Criterion.LatitudeDegrees) - -def csv_to_field_LatitudeDegrees(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(RadiusCriterion)): - setattr(entity.Criterion, "LatitudeDegrees", value) - -def field_to_csv_LongitudeDegrees(entity): - if entity is None or entity.Criterion is None or entity.Criterion.LongitudeDegrees is None: - return None - return str(entity.Criterion.LongitudeDegrees) - -def csv_to_field_LongitudeDegrees(entity, value): - if value is None or value == '': - return - if entity is not None and entity.Criterion is not None and isinstance(entity.Criterion,type(RadiusCriterion)): - setattr(entity.Criterion, "LongitudeDegrees", value) - -def target_setting_to_csv(entity): - if not entity.Settings or not entity.Settings.Setting: - return None - settings = [setting for setting in entity.Settings.Setting if isinstance(setting, TargetSetting_Type)] - if len(settings) == 0: - return None - if len(settings) != 1: - raise ValueError('Can only have 1 TargetSetting in Settings.') - target_setting = settings[0] - if not target_setting.Details.TargetSettingDetail: - return DELETE_VALUE if entity.Id and entity.Id > 0 else None - return ";".join([s.CriterionTypeGroup for s in target_setting.Details.TargetSettingDetail]) - pass - - -def csv_to_target_setting(entity, value): - target_setting = _CAMPAIGN_OBJECT_FACTORY_V12.create('TargetSetting') - target_setting.Type = 'TargetSetting' - if value is None: - entity.Settings.Setting.append(target_setting) - return - tokens = [t.strip() for t in value.split(';')] - target_setting_detail_list = [] - for token in tokens: - m_token = match_target_setting(token) - if m_token: - target_setting_detail_list.append(create_target_setting_detail(m_token)) - target_setting.Details.TargetSettingDetail.extend(target_setting_detail_list) - entity.Settings.Setting.append(target_setting) - pass - -def match_target_setting(token): - - pattern = re.compile(target_setting_detail_pattern) - m = pattern.match(token) - if m: - return m.group(1) - return None - -def create_target_setting_detail(token): - target_setting_detail = _CAMPAIGN_OBJECT_FACTORY_V12.create('TargetSettingDetail') - target_setting_detail.TargetAndBid = True - target_setting_detail.CriterionTypeGroup = token - return target_setting_detail - pass - -def parse_rule_PageVisitors(rule_str): - rule = _CAMPAIGN_OBJECT_FACTORY_V12.create('PageVisitorsRule') - rule.Type = 'PageVisitors' - rule.RuleItemGroups = parse_rule_groups(rule_str) - return rule - - -def parse_rule_PageVisitorsWhoVisitedAnotherPage(rule_str): - rule = _CAMPAIGN_OBJECT_FACTORY_V12.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 - - -def parse_rule_PageVisitorsWhoDidNotVisitAnotherPage(rule_str): - rule = _CAMPAIGN_OBJECT_FACTORY_V12.create('PageVisitorsWhoDidNotVisitAnotherPageRule') - rule.Type = 'PageVisitorsWhoDidNotVisitAnotherPage' - - groups_split = '))) and not (((' - groups_string_list = rule_str.split(groups_split) - - rule.IncludeRuleItemGroups = parse_rule_groups(groups_string_list[0]) - rule.ExcludeRuleItemGroups = parse_rule_groups(groups_string_list[1]) - - return rule - - -def parse_rule_CustomEvents(rule_str): - rule = _CAMPAIGN_OBJECT_FACTORY_V12.create('CustomEventsRule') - rule.Type = 'CustomEvents' - - item_split = ') and (' - pattern_for_operand_str = '^(Category|Action|Label|Value) ([^()]*)$' - pattern_for_operand = re.compile(pattern_for_operand_str) - - pattern_number_item_str = '^(Equals|GreaterThan|LessThan|GreaterThanEqualTo|LessThanEqualTo) ([^()]*)$' - pattern_number_item = re.compile(pattern_number_item_str) - - pattern_string_item_str = '^(Equals|Contains|BeginsWith|EndsWith|NotEquals|DoesNotContain|DoesNotBeginWith|DoesNotEndWith) ([^()]*)$' - pattern_string_item = re.compile(pattern_string_item_str) - - item_string_list = rule_str.split(item_split) - for item_string in item_string_list: - item_string = item_string.strip('(').strip(')') - match_for_operand = pattern_for_operand.match(item_string) - - if not match_for_operand: - raise ValueError('Invalid Custom Event rule item: {0}'.format(item_string)) - - operand = match_for_operand.group(1) - operater_and_value_string = match_for_operand.group(2) - - if operand.lower() == 'value': - match_number_item = pattern_number_item.match(operater_and_value_string) - - if not match_number_item: - raise ValueError('Invalid Custom Event number rule item: {0}'.format(item_string)) - - rule.ValueOperator = parse_number_operator(match_number_item.group(1)) - rule.Value = float(match_number_item.group(2)) - else: - match_string_item = pattern_string_item.match(operater_and_value_string) - - if not match_string_item: - raise ValueError('Invalid Custom Event string rule item: {0}'.format(item_string)) - - if operand.lower() == 'category': - rule.CategoryOperator = parse_string_operator(match_string_item.group(1)) - rule.Category = match_string_item.group(2) - elif operand.lower() == 'label': - rule.LabelOperator = parse_string_operator(match_string_item.group(1)) - rule.Label = match_string_item.group(2) - elif operand.lower() == 'action': - rule.ActionOperator = parse_string_operator(match_string_item.group(1)) - rule.Action = match_string_item.group(2) - else: - raise ValueError('Invalid Custom Event string rule operator: {0}'.format(operand)) - - return rule - - -def parse_rule_groups(groups_str): - group_split = ')) or ((' - group_str_list = groups_str.split(group_split) - - rule_item_groups = _CAMPAIGN_OBJECT_FACTORY_V12.create('ArrayOfRuleItemGroup') - for group_str in group_str_list: - item_group = parse_rule_items(group_str) - rule_item_groups.RuleItemGroup.append(item_group) - - return rule_item_groups - - -def parse_rule_items(items_str): - item_split = ') and (' - item_str_list = items_str.split(item_split) - - rule_item_group = _CAMPAIGN_OBJECT_FACTORY_V12.create('RuleItemGroup') - for item_str in item_str_list: - item = parse_string_rule_item(item_str) - rule_item_group.Items.RuleItem.append(item) - - return rule_item_group - - -def parse_string_rule_item(item_str): - item_str = item_str.strip('(').strip(')') - pattern_str = '^(Url|ReferrerUrl|None) (Equals|Contains|BeginsWith|EndsWith|NotEquals|DoesNotContain|DoesNotBeginWith|DoesNotEndWith) ([^()]*)$' - pattern = re.compile(pattern_str) - - match = pattern.match(item_str) - - if not match: - ValueError('Invalid Rule Item:{0}'.format(item_str)) - - item = _CAMPAIGN_OBJECT_FACTORY_V12.create('StringRuleItem') - item.Type = 'String' - item.Operand = match.group(1) - item.Operator = parse_string_operator(match.group(2)) - item.Value = match.group(3) - - return item - - -def parse_number_operator(operator): - oper = operator.lower() - if oper == 'equals': - return NumberOperator.Equals - if oper == 'greaterthan': - return NumberOperator.GreaterThan - if oper == 'lessthan': - return NumberOperator.LessThan - if oper == 'greaterthanequalto': - return NumberOperator.GreaterThanEqualTo - if oper == 'lessthanequalto': - return NumberOperator.LessThanEqualTo - raise ValueError('Invalid Number Rule Item operator:{0}'.format(operator)) - - -def parse_string_operator(operator): - oper = operator.lower() - if oper == 'equals': - return StringOperator.Equals - if oper == 'contains': - return StringOperator.Contains - if oper == 'beginswith': - return StringOperator.BeginsWith - if oper == 'endswith': - return StringOperator.EndsWith - if oper == 'notequals': - return StringOperator.NotEquals - if oper == 'doesnotcontain': - return StringOperator.DoesNotContain - if oper == 'doesnotbeginwith': - return StringOperator.DoesNotBeginWith - if oper == 'doesnotendwith': - return StringOperator.DoesNotEndWith - - raise ValueError('Invalid String Rule Item operator:{0}'.format(operator)) - - -def csv_to_field_SupportedCampaignTypes(entity, value): - if value is None or value == '': - return - splitter = re.compile(';') - entity.string = splitter.split(value) - - -def field_to_csv_SupportedCampaignTypes(entity): - if entity is None or entity.string is None: - return None - if len(entity.string) == 0: - return None - return ';'.join(entity.string) \ No newline at end of file diff --git a/bingads/v12/internal/reporting/__init__.py b/bingads/v12/internal/reporting/__init__.py deleted file mode 100644 index 8a681463..00000000 --- a/bingads/v12/internal/reporting/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .csv_reader import * -from .row_report_header import * -from .row_report_iterator import * -from .row_report import * -from .xml_report import * \ No newline at end of file diff --git a/bingads/v12/internal/reporting/csv_reader.py b/bingads/v12/internal/reporting/csv_reader.py deleted file mode 100644 index 49a55088..00000000 --- a/bingads/v12/internal/reporting/csv_reader.py +++ /dev/null @@ -1,54 +0,0 @@ -import csv -import io -from six import PY2, PY3 - -class _CsvReader: - - def __init__(self, filename, delimiter, encoding='utf-8-sig'): - self._filename = filename - self._delimiter = delimiter - - if delimiter == ',': - self._dialect = csv.excel - elif delimiter == '\t': - self._dialect = csv.excel_tab - else: - raise ValueError('Do not support delimiter: {0}', delimiter) - - self._csv_file = io.open(self.filename, encoding=encoding) - - if PY3: - self._csv_reader = csv.reader(self._csv_file, dialect=self._dialect) - elif PY2: - byte_lines = [line.encode('utf-8') for line in self._csv_file] - self._csv_reader = csv.reader(byte_lines, dialect=self._dialect) - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._csv_file.__exit__(exc_type, exc_value, traceback) - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def close(self): - self.__exit__(None, None, None) - - def next(self): - if PY3: - return next(self._csv_reader) - elif PY2: - row = next(self._csv_reader) - return [unicode(cell, encoding='utf-8') for cell in row] - - @property - def filename(self): - return self._filename - - @property - def delimiter(self): - return self._delimiter diff --git a/bingads/v12/internal/reporting/row_report.py b/bingads/v12/internal/reporting/row_report.py deleted file mode 100644 index b16af788..00000000 --- a/bingads/v12/internal/reporting/row_report.py +++ /dev/null @@ -1,14 +0,0 @@ -from .row_report_header import _RowReportHeader -from .row_report_iterator import _ReportStreamReader, _RowReportIterator - -from bingads.v12.reporting.report_contract import Report - -class _RowReport(Report): - - def __init__(self, file, format = 'Csv'): - self._stream_reader = _ReportStreamReader(file, format) - self._report_header = _RowReportHeader(self._stream_reader) - self._report_iterator = _RowReportIterator(self._stream_reader) - - def close(self): - self._stream_reader.close() \ No newline at end of file diff --git a/bingads/v12/internal/reporting/row_report_header.py b/bingads/v12/internal/reporting/row_report_header.py deleted file mode 100644 index e48db6e0..00000000 --- a/bingads/v12/internal/reporting/row_report_header.py +++ /dev/null @@ -1,120 +0,0 @@ -import re -from bingads.v12.internal.extensions import * - -class _RowReportHeader: - - def __init__(self, stream_reader): - self._regex = re.compile("^(Report Name|Report Time|Report Aggregation|Report Filter|Time Zone|Rows|Last Completed Available Day|Last Completed Available Hour|Potential Incomplete Data): (.*)$") - self._value_regex = re.compile("^(([1-9]\d*\.?\d*)|(0\.\d*[1-9]))%?$") - self._stream_reader = stream_reader - self._report_name = None - self._report_time_start = None - self._report_time_end = None - self._report_aggregation = None - self._time_zone = None - self._row_number = None - self._last_completed_available_date = None - self._report_columns = None - self._potential_incomplete_data = None - self.read_header() - - def read_header(self): - self._stream_reader.read_report_header(self) - - def parse_header(self, fields): - valid_values = list(filter(lambda x: x is not None and len(x) > 0, [s.strip() for s in fields])) - if len(valid_values) == 1 and ':' in fields[0]: - self.parse_meta(fields[0]) - return True - else: - for s in fields: - if self._value_regex.match(s): - return False - self._report_columns = fields - return True - - def parse_meta(self, header): - res = self._regex.match(header) - if res: - if res.group(1) == 'Report Name': - self._report_name = res.group(2) - elif res.group(1) == 'Report Time': - self.set_report_time(res.group(2)) - elif res.group(1) == 'Report Aggregation': - self._report_aggregation = res.group(2) - elif res.group(1) == 'Report Filter': - self._report_filter = res.group(2) - elif res.group(1) == 'Time Zone': - self._time_zone = res.group(2) - elif res.group(1) == 'Rows': - self._row_number = res.group(2) - elif res.group(1) == 'Last Completed Available Day': - self._last_completed_available_date = res.group(2) - elif res.group(1) == 'Potential Incomplete Data': - self._potential_incomplete_data = parse_bool(res.group(2)) - pass - - def set_report_time(self, report_time): - if report_time is None or report_time == '': - return - time_array = report_time.split(',') - - if len(time_array) == 1: - self._report_time_start = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - self._report_time_end = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - elif len(time_array) == 2: - self._report_time_start = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - self._report_time_end = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[1] else None - - @property - def last_completed_available_date(self): - if self._last_completed_available_date: - str_time = self._last_completed_available_date - if '(' in str_time: - str_time = str_time[:str_time.rfind('(') - 1] - - try: - return datetime.strptime(str_time, '%m/%d/%Y %I:%M:%S %p') - except Exception: - dt_tokens = str_time.split(' ') - if len(dt_tokens) > 1: - return datetime.strptime(' '.join(dt_tokens[:2]), '%m/%d/%Y %H:%M:%S') - return None - - @property - def record_count(self): - return int(self._row_number) if self._row_number else None - - - @property - def time_zone(self): - return self._time_zone - - @property - def potential_incomplete_data(self): - return self._potential_incomplete_data - -# @property -# def report_filter(self): -# return self._report_filter - - @property - def report_aggregation(self): - return self._report_aggregation - - @property - def report_name(self): - return self._report_name - - @property - def report_time_start(self): - return self._report_time_start - - @property - def report_time_end(self): - return self._report_time_end - - @property - def report_columns(self): - return self._report_columns - diff --git a/bingads/v12/internal/reporting/row_report_iterator.py b/bingads/v12/internal/reporting/row_report_iterator.py deleted file mode 100644 index e23fdc48..00000000 --- a/bingads/v12/internal/reporting/row_report_iterator.py +++ /dev/null @@ -1,197 +0,0 @@ -import re -from .csv_reader import _CsvReader -from bingads.v12.reporting.report_contract import InvalidReportColumnException - -class _RowReportRecord: - - def __init__(self, row_values): - self._row_values = row_values - - def value(self, header): - flag, result = self._row_values.try_get_value(header) - if flag: - return result - raise InvalidReportColumnException(header) - - def int_value(self, header): - try: - return int(self.value(header)) - except ValueError: - return 0 - - def float_value(self, header): - try: - return float(self.value(header)) - except ValueError: - return 0 - -class _RowReportRecordReader(): - """ Provides a method to read one row from report file""" - - def __init__(self, file_path, delimiter): - self._column_mapping = None - self._csv_reader = _CsvReader(file_path, delimiter) - - def read_next_header(self, parser): - - def remove_bom(unicode_str): - unicode_bom = u'\N{ZERO WIDTH NO-BREAK SPACE}' - if unicode_str and unicode_str[0] == unicode_bom: - unicode_str = unicode_str[1:] - return unicode_str - try: - fields = [remove_bom(header) for header in next(self._csv_reader)] - - if self.valid_header(fields) == False: - return self.read_next_header(parser) - - valid_values = list(filter(lambda x: x is not None and len(x) > 0, [s.strip() for s in fields])) - - if len(valid_values) == 0: - return False - else: - header = parser.parse_header(fields) - if len(valid_values) > 1: - if header: - self._column_mapping = dict(zip(fields, range(0, len(fields)))) - self.peek() - elif self.valid_record(fields): - # Exclude Column Header is set - self.next_object = _RowReportRecord(_RowValues(columns=fields, mappings=None)) - return False - return True - except StopIteration: - return False - - def valid_header(self, fields): - if fields is None: - return False - - valid_values = list(filter(lambda x: x is not None and len(x) > 0, [s.replace('-', '').strip() for s in fields])) - return len(valid_values) > 0 - pass - - def read_next_object(self): - if self.next_object != None: - ret = self.next_object - self.peek() - return ret - return None - - def peek(self): - self.next_object = None - try: - row_values = self._read_next_row_values() - self.next_object = _RowReportRecord(row_values) - except StopIteration: - pass - - def valid_record(self, values): - if values is None: - return False - - valid_values = list(filter(lambda x: x is not None and len(x) > 0, [s.replace('-', '').strip() for s in values])) - - if len(valid_values) == 0: - return False - if re.match(u'Total|\xa9\\d+ Microsoft Corporation. All rights reserved.*', valid_values[0]): - return False - - return True - - def __exit__(self, exc_type, exc_value, traceback): - self._csv_reader.__exit__(exc_type, exc_value, traceback) - - def close(self): - self._csv_reader.close() - - def _read_next_row_values(self): - values = next(self._csv_reader) - if self.valid_record(values) == False: - return self._read_next_row_values() - return _RowValues(columns=values, mappings=self._column_mapping) - - def _read_headers(self): - pass - -class _ReportStreamReader(): - - def __init__(self, file_path, file_type): - self._report_object_reader = _RowReportRecordReader(file_path, ',' if file_type == 'Csv' else '\t') - - def read_report_header(self, parser): - while (self._report_object_reader.read_next_header(parser) == True): - pass - pass - - def read(self): - peeked = self._report_object_reader.read_next_object() - if peeked is not None: - return peeked - self._report_object_reader.close() - return None - - def close(self): - self._report_object_reader.close() - - def __exit__(self, exc_type, exc_value, traceback): - self._report_object_reader.__exit__(exc_type, exc_value, traceback) - -class _RowReportIterator(): - - def __init__(self, stream_reader): - self._stream_reader = stream_reader - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._stream_reader.__exit__(exc_type, exc_value, traceback) - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def next(self): - ret = self._stream_reader.read() - if not ret: - raise StopIteration() - return ret - -class _RowValues: - def __init__(self, mappings=None, columns=None): - self._mappings = mappings - self._columns = columns - - def __getitem__(self, key): - return self.columns[self._mappings[key]] - - def __setitem__(self, key, value): - self.columns[self._mappings[key]] = value - - def __contains__(self, item): - return item in self.mappings - - def __len__(self): - return len(self.mappings) - - def __str__(self): - return u'{' + u', '.join([u'{0}:{1}'.format(k, self.columns[v]) for (k, v) in self.mappings.items()]) + u'}' - - def try_get_value(self, header): - if not self.mappings or header not in self.mappings: - return False, None - return True, self[header] - - def to_dict(self): - return dict([(k, self.columns[v]) for (k, v) in self.mappings.items()]) - - @property - def mappings(self): - return self._mappings - - @property - def columns(self): - return self._columns \ No newline at end of file diff --git a/bingads/v12/internal/reporting/xml_report.py b/bingads/v12/internal/reporting/xml_report.py deleted file mode 100644 index fe957d72..00000000 --- a/bingads/v12/internal/reporting/xml_report.py +++ /dev/null @@ -1,172 +0,0 @@ -import codecs -import xml.etree.cElementTree as et -import re -from bingads.v12.internal.extensions import * -from bingads.v12.reporting.report_contract import * - -''' -Implement with context.next.xml.etree.cElementTree is far more faster than xml.etree.ElementTree with python 2.7.10 -''' - -schema='' -class _XmlReportRecord: - def __init__(self, row): - self._row_values = {} - start = len(schema) - for elem in row: - self._row_values[elem.tag[start:]] = elem.attrib['value'] - - def value(self, header): - if header in self._row_values: - return self._row_values[header] - raise InvalidReportColumnException(header) - - def int_value(self, header): - return int(self.value(header)) - - def double_value(self, header): - return float(self.value(header)) - -class _XmlReportIterator(): - - def __init__(self, context, header): - self._context = context - self._header = header - self._row_pattern = schema + 'Row' - self._next_report_record = None - self.move_to_next_row() - - def move_to_next_row(self): - for event, elem in self._context: - if event == 'end' and self._row_pattern == elem.tag: - self._next_report_record = _XmlReportRecord(elem) - # self.try_set_report_columns(elem) - elem.clear - break - def try_set_report_columns(self, element): - if len(self._header._report_columns) == 0: - start = len(schema) - for e in element: - self._header._report_columns.append(e.tag[start:]) - - - def __enter__(self): - return self - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def next(self): - if self._next_report_record == None: - raise StopIteration() - - ret = self._next_report_record - self._next_report_record = None - self.move_to_next_row() - return ret - - -class _XmlReportHeader: - - def __init__(self, context): - self._report_columns = [] - if context is not None: - event, root = context.next() - if event == 'start': - m = re.compile('^(.*)Report').match(root.tag) - if not m: - raise InvalidReportContentException() - self.set_report_attribute(root.attrib.copy()) - global schema - schema = m.group(1) - root.clear() - self.parse_column_names(context) - - def set_report_attribute(self, report_attr): - self._report_attr = report_attr - self.set_report_time() - - def set_report_time(self): - self._report_time_start = None - self._report_time_end = None - if 'ReportTime' in self._report_attr: - time_array = self._report_attr['ReportTime'].split(',') - - if len(time_array) == 1: - self._report_time_start = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - self._report_time_end = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - elif len(time_array) == 2: - self._report_time_start = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[0] else None - self._report_time_end = datetime.strptime(time_array[0], '%m/%d/%Y') if time_array[1] else None - - def parse_column_names(self, context): - for event, elem in context: - if event == 'start' and schema + 'Column' == elem.tag: - self._report_columns.append(elem.attrib['name']) - elem.clear() - elif event == 'start' and 'Table' in elem.tag: - # in case there is no columns names - ExcludeColumnHeader is set to true. - break - - @property - def last_completed_available_date(self): - if 'LastCompletedAvailableDay' in self._report_attr: - str_time = self._report_attr['LastCompletedAvailableDay'] - if '(' in str_time: - str_time = str_time[:str_time.rfind('(') - 1] - - try: - return datetime.strptime(str_time, '%m/%d/%Y %I:%M:%S %p') - except Exception: - dt_tokens = str_time.split(' ') - if len(dt_tokens) > 1: - return datetime.strptime(' '.join(dt_tokens[:2]), '%m/%d/%Y %H:%M:%S') - return None - - @property - def record_count(self): - return int(self._report_attr['Rows']) if 'Rows' in self._report_attr else None - - @property - def time_zone(self): - return self._report_attr['TimeZone'] if 'TimeZone' in self._report_attr else None - -# @property -# def report_filter(self): -# return None - - @property - def report_aggregation(self): - return self._report_attr['ReportAggregation'] if 'ReportAggregation' in self._report_attr else None - - @property - def report_name(self): - return self._report_attr['ReportName'] if 'ReportName' in self._report_attr else None - - @property - def potential_incomplete_data(self): - return parse_bool(self._report_attr['PotentialIncompleteData']) if 'PotentialIncompleteData' in self._report_attr else None - - @property - def report_time_start(self): - return self._report_time_start - - @property - def report_time_end(self): - return self._report_time_end - - @property - def report_columns(self): - return self._report_columns - - - -class _XmlReport(Report): - - def __init__(self, file): - context = et.iterparse(file, events=("start", "end")) - self._report_header = _XmlReportHeader(context) - self._report_iterator = _XmlReportIterator(context, self._report_header) diff --git a/bingads/v12/proxies/campaign_management_service.xml b/bingads/v12/proxies/campaign_management_service.xml deleted file mode 100644 index 44c5a354..00000000 --- a/bingads/v12/proxies/campaign_management_service.xml +++ /dev/null @@ -1,10492 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - 3 - - - - - - - 4 - - - - - - - 5 - - - - - - - 6 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - 3 - - - - - - - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 - - - - - - - 8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - - - - - - 4 - - - - - - - 8 - - - - - - - 16 - - - - - - - 32 - - - - - - - 64 - - - - - - - 128 - - - - - - - 256 - - - - - - - 512 - - - - - - - 1024 - - - - - - - 2048 - - - - - - - 4096 - - - - - - - 8192 - - - - - - - 16384 - - - - - - - 32768 - - - - - - - 65536 - - - - - - - 131072 - - - - - - - 262144 - - - - - - - 524288 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - 1 - - - - - - - 2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - 2 - - - - - - - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 - - - - - - - 8 - - - - - - - 16 - - - - - - - 32 - - - - - - - 64 - - - - - - - 128 - - - - - - - 256 - - - - - - - 512 - - - - - - - 1024 - - - - - - - 2048 - - - - - - - 4096 - - - - - - - 8192 - - - - - - - 16384 - - - - - - - 32768 - - - - - - - 65536 - - - - - - - 131072 - - - - - - - 262144 - - - - - - - 524288 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bingads/v12/reporting/__init__.py b/bingads/v12/reporting/__init__.py deleted file mode 100644 index f40c5469..00000000 --- a/bingads/v12/reporting/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -__author__ = 'Bing Ads SDK Team' -__email__ = 'bing_ads_sdk@microsoft.com' - -from .reporting_download_parameters import * -from .exceptions import * -from .reporting_operation import * -from .reporting_operation_status import * -from .reporting_service_manager import * -from .report_contract import * -from .report_file_reader import * \ No newline at end of file diff --git a/bingads/v12/reporting/exceptions.py b/bingads/v12/reporting/exceptions.py deleted file mode 100644 index 563b14ee..00000000 --- a/bingads/v12/reporting/exceptions.py +++ /dev/null @@ -1,85 +0,0 @@ -from ...exceptions import SdkException - - -class ReportingException(SdkException): - def __init__(self, message, errors): - super(ReportingException, self).__init__(message) - self._errors = errors - - @property - def errors(self): - """ The list of operation errors returned by the reporting service. - - :rtype: list[OperationError] - """ - return self._errors - - -class ReportingDownloadException(SdkException): - def __init__(self, message): - super(ReportingDownloadException, self).__init__(message) - - -class OperationError: - """ Defines an error object that contains the details that explain why the service operation failed. """ - - def __init__(self, - code=None, - details=None, - error_code=None, - message=None,): - self._code = code - self._details = details - self._error_code = error_code - self._message = message - - @property - def code(self): - """ A numeric error code that identifies the error - - :rtype: int - """ - - return self._code - - @code.setter - def code(self, value): - self._code = value - - @property - def details(self): - """ A message that provides additional details about the error. This string can be empty. - - :rtype: str - """ - - return self._details - - @details.setter - def details(self, value): - self._details = value - - @property - def error_code(self): - """ A symbolic string constant that identifies the error. For example, UserIsNotAuthorized. - - :rtype: str - """ - - return self._error_code - - @error_code.setter - def error_code(self, value): - self._error_code = value - - @property - def message(self): - """ A message that describes the error. - - :rtype: str - """ - return self._message - - @message.setter - def message(self, value): - self._message = value diff --git a/bingads/v12/reporting/report_contract.py b/bingads/v12/reporting/report_contract.py deleted file mode 100644 index 94e554ec..00000000 --- a/bingads/v12/reporting/report_contract.py +++ /dev/null @@ -1,83 +0,0 @@ -from bingads.exceptions import SdkException - -class Report: - - def __init__(self): - self._report_header = None - self._report_iterator = None - pass - - @property - def report_name(self): - return self._report_header.report_name - - @property - def last_completed_available_date(self): - return self._report_header.last_completed_available_date - - @property - def record_count(self): - return self._report_header.record_count - - @property - def time_zone(self): - return self._report_header.time_zone - -# @property -# def report_filter(self): -# return self._report_header.report_filter - - @property - def potential_incomplete_data(self): - return self._report_header.potential_incomplete_data - - @property - def report_aggregation(self): - return self._report_header.report_aggregation - - @property - def report_time_start(self): - return self._report_header.report_time_start - - @property - def report_time_end(self): - return self._report_header.report_time_end - - @property - def report_columns(self): - return self._report_header.report_columns - - @property - def report_records(self): - return self._report_iterator - - def close(self): - pass - - -class InvalidReportFormatException(SdkException): - - def __init__(self, format): - """ Initializes a new instance of this class with the specified error messages. - - :param format: The format of the report file to read. - :type format: str - """ - super(InvalidReportFormatException, self).__init__(str.format("Report format {0} is not supported.", format)) - -class InvalidReportContentException(SdkException): - - def __init__(self): - super(InvalidReportContentException, self).__init__("Report content is invalid.") - - -class InvalidReportColumnException(SdkException): - """ This exception is thrown if trying to retrieve inexistent column """ - - def __init__(self, column_name): - """ Initializes a new instance of this class with the specified error messages. - - :param column_name: The column name to be retrieved from the report. - :type column_name: str - """ - super(InvalidReportColumnException, self).__init__(str.format("Field: {0} does not exist in report.", column_name)) \ No newline at end of file diff --git a/bingads/v12/reporting/report_file_reader.py b/bingads/v12/reporting/report_file_reader.py deleted file mode 100644 index 16b5608b..00000000 --- a/bingads/v12/reporting/report_file_reader.py +++ /dev/null @@ -1,34 +0,0 @@ -from bingads.v12.internal.reporting.row_report import _RowReport -from bingads.v12.internal.reporting.xml_report import _XmlReport -from .report_contract import InvalidReportFormatException - -class ReportFileReader: - def __init__(self, file_path, format): - if format is None: - return - self._file_path = file_path - lower = format.lower() - if lower == 'csv': - self._report = _RowReport(file_path, format = 'Csv') - elif lower == 'tsv': - self._report = _RowReport(file_path, format = 'Tsv') - elif lower == 'xml': - self._report = _XmlReport(file_path) - else: - raise InvalidReportFormatException(format) - - def get_report(self): - return self._report - - @property - def file_path(self): - """ The path of the bulk file to read. - - :rtype: str - """ - - return self._file_path - - def close(self): - self._report.close() - self._report = None \ No newline at end of file diff --git a/bingads/v12/reporting/reporting_download_parameters.py b/bingads/v12/reporting/reporting_download_parameters.py deleted file mode 100644 index 417265db..00000000 --- a/bingads/v12/reporting/reporting_download_parameters.py +++ /dev/null @@ -1,107 +0,0 @@ -import os - - -class ReportingDownloadParameters: - """ Describes the related parameters when downloading file from server. - - such as the file name and directory that you want to specify. - """ - - def __init__(self, - report_request=None, - result_file_directory=None, - result_file_name=None, - overwrite_result_file=False, - timeout_in_milliseconds=None): - """ - :param report_request: the report request object, which derives from the base request report class - :type report_request: ReportRequest - :param result_file_directory: (optional) The directory where the file will be downloaded. - :type result_file_directory: str - :param result_file_name: (optional) The name of the download result file. - :type result_file_name: str - :param overwrite_result_file: - :type overwrite_result_file: bool - :param timeout_in_milliseconds: (optional) timeout for reporting download operations in milliseconds - :type timeout_in_milliseconds: int - :return: - """ - - self._report_request = report_request - self._result_file_directory = result_file_directory - self._result_file_name = result_file_name - self._decompress_result_file = True - if result_file_name is not None: - _, ext = os.path.splitext(result_file_name) - if ext == '.zip': - self._decompress_result_file = False - self._overwrite_result_file = overwrite_result_file - self._timeout_in_milliseconds=timeout_in_milliseconds - - @property - def result_file_directory(self): - """ The directory where the reporting file will be downloaded. - :rtype: str - """ - - return self._result_file_directory - - @property - def result_file_name(self): - """ The name of the download reporting file. - :rtype: str - """ - - return self._result_file_name - - @property - def overwrite_result_file(self): - """ Whether the local result file should be overwritten if it already exists. - :rtype: bool - """ - - return self._overwrite_result_file - - @result_file_directory.setter - def result_file_directory(self, result_file_directory): - self._result_file_directory = result_file_directory - - @result_file_name.setter - def result_file_name(self, result_file_name): - self._result_file_name = result_file_name - - @overwrite_result_file.setter - def overwrite_result_file(self, overwrite): - self._overwrite_result_file = overwrite - - @property - def decompress_result_file(self): - """ If need to decompress the result file after download. - This property is determined by the result_file_name, by default will do decompression. - if the result_file_name has the extension of '.zip' then do not do decompression. - :rtype: bool - """ - - return self._decompress_result_file - - - @property - def report_request(self): - """ The report request. - :rtype: ReportRequest - """ - - return self._report_request - - - @report_request.setter - def report_request(self, value): - self._report_request = value - - @property - def timeout_in_milliseconds(self): - return self._timeout_in_milliseconds - - @timeout_in_milliseconds.setter - def timeout_in_milliseconds(self, value): - self._timeout_in_milliseconds = value diff --git a/bingads/v12/reporting/reporting_operation.py b/bingads/v12/reporting/reporting_operation.py deleted file mode 100644 index 3a1a66ed..00000000 --- a/bingads/v12/reporting/reporting_operation.py +++ /dev/null @@ -1,230 +0,0 @@ -import time -import contextlib -import ssl -import requests -import zipfile -import os -import six -import sys -import shutil - -from .reporting_operation_status import * -from .exceptions import * -from bingads.util import _PollingBlocker, errorcode_of_exception, ratelimit_retry_duration -from bingads.exceptions import * - -from ...service_client import ServiceClient -from ...manifest import * - -from requests.adapters import HTTPAdapter -from requests.packages.urllib3.poolmanager import PoolManager - - -class TlsHttpAdapter(HTTPAdapter): - """" Transport adapter that chooses the TLS protocols based on python versions. """ - - def init_poolmanager(self, connections, maxsize, block=False): - self.poolmanager = PoolManager( - num_pools=connections, - maxsize=maxsize, - block=block, - ssl_version=ssl.PROTOCOL_SSLv23 - ) - - -class ReportingDownloadOperation(object): - """ Represents a reporting download operation requested by a user. - - You can use this class to poll for the download status, and then download the file when available. - - *Example:* - - The :meth:`.ReportingServiceManager.submit_download` method returns an instance of this class. - If for any reason you do not want to wait for the file to be prepared for download, - for example if your application quits unexpectedly or you have other tasks to process, you can - use an instance of :class:`.ReportingDownloadOperation` to download the file when it is available. - """ - - def __init__(self, - request_id, - authorization_data, - poll_interval_in_milliseconds=5000, - environment='production', - tracking_id=None, - **suds_options): - self._request_id = request_id - self._service_client = ServiceClient('ReportingService', 12, authorization_data, environment, **suds_options) - self._authorization_data = authorization_data - self._poll_interval_in_milliseconds = poll_interval_in_milliseconds - self._final_status = None - self.tracking_id=tracking_id - - def download_result_file(self, result_file_directory, result_file_name, decompress, overwrite, timeout_in_milliseconds=None): - """ Download file with specified URL and download parameters. - - :param result_file_directory: The download result local directory name. - :type result_file_directory: str - :param result_file_name: The download result local file name. - :type result_file_name: str | None - :param decompress: Determines whether to decompress the ZIP file. - If set to true, the file will be decompressed after download. - The default value is false, in which case the downloaded file is not decompressed. - :type decompress: bool - :param overwrite: Indicates whether the result file should overwrite the existing file if any. - :type overwrite: bool - :return: The download file path. - :rtype: str - :param timeout_in_milliseconds: (optional) timeout for download result file in milliseconds - :type timeout_in_milliseconds: int - """ - - if result_file_directory is None: - raise ValueError('result_file_directory cannot be None.') - - url = self.final_status.report_download_url - - if url is None or url == '': - return None - - if result_file_name is None: - result_file_name = self.request_id - - if decompress: - name, ext = os.path.splitext(result_file_name) - if ext == '.zip': - raise ValueError("Result file can't be decompressed into a file with extension 'zip'." - " Please change the extension of the result_file_name or pass decompress_result_file = false") - zip_file_path = os.path.join(result_file_directory, name + '.zip') - result_file_path = os.path.join(result_file_directory, result_file_name) - else: - result_file_path = os.path.join(result_file_directory, result_file_name) - zip_file_path = result_file_path - - if os.path.exists(result_file_path) and overwrite is False: - if six.PY3: - raise FileExistsError('Result file: {0} exists'.format(result_file_path)) - else: - raise OSError('Result file: {0} exists'.format(result_file_path)) - headers = { - 'User-Agent': USER_AGENT, - } - s = requests.Session() - s.mount('https://', TlsHttpAdapter()) - timeout_seconds = None if timeout_in_milliseconds is None else timeout_in_milliseconds / 1000.0 - try: - r = s.get(url, headers=headers, stream=True, verify=True, timeout=timeout_seconds) - except requests.Timeout as ex: - raise FileDownloadException(ex) - r.raise_for_status() - try: - with open(zip_file_path, 'wb') as f: - for chunk in r.iter_content(chunk_size=4096): - if chunk: - f.write(chunk) - f.flush() - if decompress: - with contextlib.closing(zipfile.ZipFile(zip_file_path)) as compressed: - first = compressed.namelist()[0] - with open(result_file_path, 'wb') as f, compressed.open(first, 'r') as cc: - shutil.copyfileobj(cc, f) - except Exception as ex: - raise ex - finally: - if decompress and os.path.exists(zip_file_path): - os.remove(zip_file_path) - return result_file_path - - def track(self, timeout_in_milliseconds=None): - """ Runs until the reporting service has finished processing the download or upload request. - - :param timeout_in_milliseconds: (optional) timeout for tracking reporting download operation - :type timeout_in_milliseconds: int - :return: The final ReportingOperationStatus. - :rtype: ReportingOperationStatus - """ - - if self.final_status is not None: - return self.final_status - blocker = _PollingBlocker(self.poll_interval_in_milliseconds, timeout_in_milliseconds) - blocker.wait() - while True: - status = self.get_status() - if status.status == 'Pending': - blocker.wait() - continue - if status.status != 'Success': - raise ReportingException('Exceptions while reporting download.', status.status) - self._final_status = status - return self._final_status - - def get_status(self): - """ Track the detailed download status. - - :return: The status of reporting download operation. - :rtype: ReportingOperationStatus - """ - if self.final_status is not None: - return self.final_status - response = self._get_status_with_retry(4) - headers = self.service_client.get_response_header() - self.tracking_id = headers['TrackingId'] if 'TrackingId' in headers else None - status = ReportingOperationStatus( - status=response.Status, - report_download_url=response.ReportDownloadUrl - ) - if status.status == 'Success' or \ - status.status == 'Error': - self._final_status = status - return status - - def _get_status_with_retry(self, retry_times): - while retry_times > 1: - try: - return self.service_client.PollGenerateReport(self.request_id) - except Exception as ex: - retry_times -= 1 - if '117' == errorcode_of_exception(ex): - time.sleep(ratelimit_retry_duration[3 - retry_times]) - else: - time.sleep(1) - return self.service_client.PollGenerateReport(self.request_id) - - @property - def request_id(self): - """ The request identifier corresponding to the reporting download, depending on the derived type. - - :rtype: str - """ - - return self._request_id - - @property - def final_status(self): - """ Gets the final status of the reporting operation or null if the operation is still running. - - :rtype: ReportingOperationStatus - """ - - return self._final_status - - @property - def service_client(self): - """ The internal reporting service client. - - :rtype: ServiceClient - """ - - return self._service_client - - @property - def poll_interval_in_milliseconds(self): - """ The time interval in milliseconds between two status polling attempts. - - :rtype: int - """ - - return self._poll_interval_in_milliseconds - - @poll_interval_in_milliseconds.setter - def poll_interval_in_milliseconds(self, poll_interval): - self._poll_interval_in_milliseconds = poll_interval diff --git a/bingads/v12/reporting/reporting_operation_status.py b/bingads/v12/reporting/reporting_operation_status.py deleted file mode 100644 index f60f087b..00000000 --- a/bingads/v12/reporting/reporting_operation_status.py +++ /dev/null @@ -1,39 +0,0 @@ -class ReportingOperationStatus(object): - """ Contains tracking details about the Report Request Status """ - - def __init__(self, - status=None, - report_download_url=None): - """ Initialize a new instance of this class. - - :param status: (optional) The download or upload status. - :type status: str - :param report_download_url: (optional) The report download Url. - :type report_download_url: str - """ - - self._status = status - self._report_download_url = report_download_url - - @property - def status(self): - """ The download status. - :rtype: str - """ - return self._status - - @status.setter - def status(self, value): - self._status = value - - - @property - def report_download_url(self): - """ The report download Url. - :rtype: str - """ - return self._report_download_url - - @report_download_url.setter - def report_download_url(self, value): - self._report_download_url = value diff --git a/bingads/v12/reporting/reporting_service_manager.py b/bingads/v12/reporting/reporting_service_manager.py deleted file mode 100644 index a4b520a1..00000000 --- a/bingads/v12/reporting/reporting_service_manager.py +++ /dev/null @@ -1,178 +0,0 @@ -import tempfile - -from .reporting_operation import * -from .report_file_reader import * -from ...manifest import * -from ...service_client import ServiceClient -from ...exceptions import TimeoutException -from ...util import _TimeHelper - -class ReportingServiceManager: - """ Provides high level methods for downloading reporting files using the Reporting API functionality. - - Also provides methods for submitting download operations. - - *Example:* - - :func:`download_file` will submit the download request to the reporting service, - poll until the status is completed (or returns an error), and downloads the file locally. - If instead you want to manage the low level details you would first call :func:`submit_download`, - wait for the results file to be prepared using either :meth:`.ReportingDownloadOperation.get_status` - or :meth:`.ReportingDownloadOperation.track`, and then download the file with the - :meth:`.ReportingOperation.download_result_file` method. - """ - def __init__(self, authorization_data, poll_interval_in_milliseconds=5000, environment='production', working_directory=None, **suds_options): - """ Initialize a new instance of this class. - - :param authorization_data: Represents a user who intends to access the corresponding customer and account. - :type authorization_data: AuthorizationData - :param environment: (optional) Represents which API environment to use, default is `production`, you can also pass `sandbox` in - :type environment: str - :param poll_interval_in_milliseconds: (optional) The time interval in milliseconds between two status polling attempts. - The default value is 15000 milliseconds. - :type poll_interval_in_milliseconds: int - :param working_directory: (optional) Directory for storing temporary files needed for some operations - (for example :func:`upload_entities` creates a temporary upload file). - :param suds_options: The suds options need to pass to suds client - """ - - self._environment = environment - self._service_client = ServiceClient('ReportingService', 12, authorization_data, environment, **suds_options) - self._authorization_data = authorization_data - self._poll_interval_in_milliseconds = poll_interval_in_milliseconds - self._working_directory = os.path.join(tempfile.gettempdir(), WORKING_NAME) - if working_directory is not None: - self._working_directory = working_directory - # make sure the working directory exists or create it. - if not os.path.exists(self._working_directory): - os.makedirs(self._working_directory) - self._suds_options = suds_options - - def download_report(self, download_parameters): - """ Downloads the specified reporting to a local file and parse it with report_file_reader. - - :param download_parameters: Determines various download parameters, for example where the file should be downloaded. - :type download_parameters: ReportingDownloadParameters - :return: Report object parsed from the downloaded local reporting file path. - :rtype: Report - """ - report_file_path = self.download_file(download_parameters) - if report_file_path: - reader = ReportFileReader(report_file_path, download_parameters.report_request.Format) - return reader.get_report() - - - def download_file(self, download_parameters): - """ Downloads the specified reporting to a local file. - - :param download_parameters: Determines various download parameters, for example where the file should be downloaded. - :type download_parameters: ReportingDownloadParameters - :return: The downloaded local reporting file path. - :rtype: str - """ - - start_timestamp = _TimeHelper.get_current_time_milliseconds() - operation = self.submit_download(download_parameters.report_request) - try: - operation.track(download_parameters.timeout_in_milliseconds) - except TimeoutException: - raise ReportingDownloadException("Reporting file download tracking status timeout.") - result_file_directory = self.working_directory - if download_parameters.result_file_directory is not None: - result_file_directory = download_parameters.result_file_directory - download_result_file_timeout = _TimeHelper.get_remaining_time_milliseconds_with_min_value(start_timestamp, download_parameters.timeout_in_milliseconds) - result_file_path = operation.download_result_file( - result_file_directory=result_file_directory, - result_file_name=download_parameters.result_file_name, - decompress=download_parameters.decompress_result_file, - overwrite=download_parameters.overwrite_result_file, - timeout_in_milliseconds=download_result_file_timeout, - ) - return result_file_path - - def submit_download(self, report_request): - """ Submits a download request to the Bing Ads reporting service with the specified request. - - :param report_request: Determines what kind of reporting file to download - :type report_request: ReportRequest - :return: The submitted download operation - :rtype: ReportingDownloadOperation - """ - self.normalize_request(report_request) - response = self.service_client.SubmitGenerateReport(report_request) - headers = self.service_client.get_response_header() - operation = ReportingDownloadOperation( - request_id=response, - authorization_data=self._authorization_data, - poll_interval_in_milliseconds=self._poll_interval_in_milliseconds, - environment=self._environment, - tracking_id = headers['TrackingId'] if 'TrackingId' in headers else None, - **self.suds_options - ) - return operation - - def normalize_request(self, report_request): - - if report_request is None: - return - - if not hasattr(report_request, 'Time'): - return - - - if hasattr(report_request.Time, 'ReportTimeZone') \ - and hasattr(report_request.Time.ReportTimeZone, 'value') \ - and report_request.Time.ReportTimeZone.value is None: - report_request.Time.ReportTimeZone=None - - if hasattr(report_request.Time, 'PredefinedTime') \ - and hasattr(report_request.Time.PredefinedTime, 'value') \ - and report_request.Time.PredefinedTime.value is None: - report_request.Time.PredefinedTime=None - - @property - def service_client(self): - """ The internal reporting service client. - - :rtype: ServiceClient - """ - - return self._service_client - - @property - def poll_interval_in_milliseconds(self): - """ The time interval in milliseconds between two status polling attempts. - - :rtype: int - """ - - return self._poll_interval_in_milliseconds - - @poll_interval_in_milliseconds.setter - def poll_interval_in_milliseconds(self, poll_interval): - self._poll_interval_in_milliseconds = poll_interval - - @property - def working_directory(self): - """ Directory for storing temporary files needed for some operations (for example :func:`upload_entities` creates a temporary upload file). - - :rtype: str - """ - - return self._working_directory - - @working_directory.setter - def working_directory(self, value): - self._working_directory = value - - @property - def suds_options(self): - """ suds option parameters - - :return: dict - """ - return self._suds_options - - @suds_options.setter - def suds_options(self, value): - self._suds_options = value diff --git a/bingads/v13/bulk/entities/bulk_account.py b/bingads/v13/bulk/entities/bulk_account.py index 456f1602..6f3c99d4 100644 --- a/bingads/v13/bulk/entities/bulk_account.py +++ b/bingads/v13/bulk/entities/bulk_account.py @@ -24,6 +24,8 @@ def __init__(self, account_id=None, customer_id=None, sync_time=None): self._customer_id = customer_id self._sync_time = sync_time self._msclkid_auto_tagging_enabled = None + self._include_view_through_conversions = None + self._profile_expansion_enabled = None self._tracking_url_template = None self._final_url_suffix = None @@ -72,6 +74,22 @@ def msclkid_auto_tagging_enabled(self): """ return self._msclkid_auto_tagging_enabled + @property + def include_view_through_conversions(self): + """ + :return: The 'Include View Through Conversions' field of the account + :rtype: bool + """ + return self._include_view_through_conversions + + @property + def profile_expansion_enabled(self): + """ + :return: The 'Profile Expansion Enabled' field of the account + :rtype: bool + """ + return self._profile_expansion_enabled + @property def tracking_url_template(self): """ The tracking template to use as a default for all URLs in your account. @@ -125,6 +143,16 @@ def final_url_suffix(self, v): field_to_csv=lambda c: bulk_optional_str(c.final_url_suffix, c.id), csv_to_field=lambda c, v: setattr(c, '_final_url_suffix', v) ), + _SimpleBulkMapping( + header=_StringTable.IncludeViewThroughConversions, + field_to_csv=lambda c: bulk_str(c.include_view_through_conversions), + csv_to_field=lambda c, v: setattr(c, '_include_view_through_conversions', parse_bool(v)) + ), + _SimpleBulkMapping( + header=_StringTable.ProfileExpansionEnabled, + field_to_csv=lambda c: bulk_str(c.profile_expansion_enabled), + csv_to_field=lambda c, v: setattr(c, '_profile_expansion_enabled', parse_bool(v)) + ), ] def process_mappings_from_row_values(self, row_values): diff --git a/bingads/v13/bulk/entities/feeds/bulk_feed_item.py b/bingads/v13/bulk/entities/feeds/bulk_feed_item.py index b5b09aab..1be15ee0 100644 --- a/bingads/v13/bulk/entities/feeds/bulk_feed_item.py +++ b/bingads/v13/bulk/entities/feeds/bulk_feed_item.py @@ -60,6 +60,8 @@ def __init__(self): self._location_id = None self._intent_option = None self._device_preference = None + self._adgroup_id = None + self._campaign_id = None @@ -139,6 +141,16 @@ def __init__(self): field_to_csv=lambda c: field_to_csv_FeedItemAdSchedule(c, c.id), csv_to_field=lambda c, v: csv_to_field_FeedItemAdSchedule(c, v) ), + _SimpleBulkMapping( + header=_StringTable.TargetAdGroupId, + field_to_csv=lambda c: bulk_optional_str(c.adgroup_id, c.id), + csv_to_field=lambda c, v: setattr(c, 'adgroup_id', int(v) if v else '') + ), + _SimpleBulkMapping( + header=_StringTable.TargetCampaignId, + field_to_csv=lambda c: bulk_optional_str(c.campaign_id, c.id), + csv_to_field=lambda c, v: setattr(c, 'campaign_id', int(v) if v else '') + ), ] @@ -180,7 +192,33 @@ def location_id(self): @location_id.setter def location_id(self, value): self._location_id = value + + + @property + def adgroup_id(self): + """ the id of the account which contains the feed + Corresponds to the 'Target Ad Group Id' field in the bulk file. + + :rtype: long + """ + return self._adgroup_id + + @adgroup_id.setter + def adgroup_id(self, value): + self._adgroup_id = value + + @property + def campaign_id(self): + """ the id of the account which contains the feed + Corresponds to the 'Target Campaign Id' field in the bulk file. + + :rtype: long + """ + return self._campaign_id + @campaign_id.setter + def campaign_id(self, value): + self._campaign_id = value @property def match_type(self): diff --git a/bingads/v13/internal/bulk/csv_headers.py b/bingads/v13/internal/bulk/csv_headers.py index 567eb771..d12e07a8 100644 --- a/bingads/v13/internal/bulk/csv_headers.py +++ b/bingads/v13/internal/bulk/csv_headers.py @@ -334,6 +334,8 @@ class _CsvHeaders: # Account _StringTable.MSCLKIDAutoTaggingEnabled, + _StringTable.IncludeViewThroughConversions, + _StringTable.ProfileExpansionEnabled, _StringTable.FinalUrlSuffix, @@ -341,7 +343,8 @@ class _CsvHeaders: _StringTable.CustomAttributes, _StringTable.FeedName, _StringTable.PhysicalIntent, - + _StringTable.TargetAdGroupId, + _StringTable.TargetCampaignId ] @staticmethod diff --git a/bingads/v13/internal/bulk/string_table.py b/bingads/v13/internal/bulk/string_table.py index 5d3811c4..9b59f144 100644 --- a/bingads/v13/internal/bulk/string_table.py +++ b/bingads/v13/internal/bulk/string_table.py @@ -56,6 +56,8 @@ class _StringTable: Feed = "Feed" FeedItem = "Feed Item" FeedName = "Feed Name" + TargetAdGroupId = 'Target Ad Group Id' + TargetCampaignId = 'Target Campaign Id' CustomAttributes = "Custom Attributes"; PageFeedIds = "Page Feed Ids"; PhysicalIntent = "Physical Intent" @@ -78,6 +80,8 @@ class _StringTable: MSCLKIDAutoTaggingEnabled = "MSCLKID Auto Tagging Enabled" LastModifiedTime = "Modified Time" AdFormatPreference = "Ad Format Preference" + IncludeViewThroughConversions = "Include View Through Conversions" + ProfileExpansionEnabled = "Profile Expansion Enabled" # Entity Types SemanticVersion = "Format Version" diff --git a/bingads/v13/proxies/campaign_management_service.xml b/bingads/v13/proxies/campaign_management_service.xml index 6926fee7..1f1be5d6 100644 --- a/bingads/v13/proxies/campaign_management_service.xml +++ b/bingads/v13/proxies/campaign_management_service.xml @@ -1531,6 +1531,20 @@ + + + + 16 + + + + + + + 32 + + + @@ -4200,6 +4214,7 @@ + @@ -4219,6 +4234,16 @@ + + + + + + + + + + @@ -4246,6 +4271,13 @@ + + + + + + + @@ -4386,6 +4418,7 @@ + diff --git a/make.py b/make.py index adf65a6b..9b277d96 100644 --- a/make.py +++ b/make.py @@ -156,16 +156,6 @@ def ut(): def ft(): run_cmd('py.test -k "functional" -v --strict') - -@task('run all v12 unit tests under current interpreter, and print coverage report') -def v12_ut(): - run_cmd('coverage run --source bingads -m py.test v12tests/ -k "not functional" -v --strict') - run_cmd('coverage report') - -@task('run all v12 functional tests under current interpreter.') -def v12_ft(): - run_cmd('py.test v12tests/ -k "functional" -v --strict') - @task('run all v13 unit tests under current interpreter, and print coverage report') def v13_ut(): run_cmd('coverage run --source bingads -m py.test v13tests/ -k "not functional" -v --strict') diff --git a/setup.py b/setup.py index 0a7f317b..fd569bc0 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ except ImportError: from distutils.core import setup -VERSION = '12.13.6' +VERSION = '13.0.1' with open('README.rst', 'r') as f: readme = f.read() @@ -29,18 +29,6 @@ packages=[ 'bingads', 'bingads.internal', - 'bingads.v12', - 'bingads.v12.bulk', - 'bingads.v12.bulk.entities', - 'bingads.v12.bulk.entities.ad_extensions', - 'bingads.v12.bulk.entities.audiences', - 'bingads.v12.bulk.entities.target_criterions', - 'bingads.v12.bulk.entities.labels', - 'bingads.v12.internal', - 'bingads.v12.internal.bulk', - 'bingads.v12.internal.bulk.entities', - 'bingads.v12.internal.reporting', - 'bingads.v12.reporting', 'bingads.v13', 'bingads.v13.bulk', 'bingads.v13.bulk.entities',