if create_ads:
# Initialize BatchJobHelper.
client = adwords.AdWordsClient.LoadFromStorage(yaml_path)
batch_job_helper = client.GetBatchJobHelper(version='v201802')
# Create a BatchJob.
batch_job = campaign_batch_upload.AddBatchJob(client)
# Retrieve the URL used to upload the BatchJob operations.
upload_url = batch_job['uploadUrl']['url']
batch_job_id = batch_job['id']
print ('Created BatchJob with ID "%d", status "%s", and upload URL "%s"' % (
batch_job['id'], batch_job['status'], upload_url))
# Generate operations to upload.
ad_operations = campaign_batch_upload.BuildAdGroupAdOperations(
batch_job_helper, create_ads)
# Upload operations.
batch_job_helper.UploadOperations(
upload_url, ad_operations)
# Download and display results.
download_url = campaign_batch_upload.GetBatchJobDownloadUrlWhenReady(client, batch_job_id)
response = requests.get(download_url).content
campaign_batch_upload.PrintResponse(batch_job_helper, response)
helpers.update_ad_id(response)
else:
print('Not ads to create')