Hi,
Im using the API in order to upload keywords to adgroups.
I have ~100000 and when Im using the batch job service is too slow( 
sometimes the server crashs before).
I red the API documentation but cant find a better way that im using
My question is:
1. Is there a better way to upload all these content in batch job.
2. Is there a limit to upload operations in batch job.

This is my code(took from examples) in python:

def run_operations_as_batch_job(account_id, wait_for_response=False, 
*operations):
    set_adwords_client(account_id)
    job_helper = adwords_client.GetBatchJobHelper()
    job = create_batch_job()
    upload_url = job['uploadUrl']['url']
    batch_job_id = job['id']

    job_helper.UploadOperations(upload_url, *operations)
    while wait_for_response:
        try:
            sleep(5)
            url = GetBatchJobDownloadUrlWhenReady(batch_job_id)
            response = urllib2.urlopen(url).read()
            return job_helper.ParseResponse(response)
        except:
            pass
    return batch_job_id


def GetBatchJobDownloadUrlWhenReady(batch_job_id, max_poll_attempts=10):
    batch_job = get_batch_job(batch_job_id)
    poll_attempt = 0
    while poll_attempt < max_poll_attempts and batch_job['status'] in ('DONE', 
'ACTIVE', 'AWAITING_FILE', 'CANCELING'):
        if 'downloadUrl' in batch_job:
            url = batch_job['downloadUrl']['url']
            print ('Batch Job with Id "%s", Status "%s", and DownloadUrl "%s" 
ready.'
                   % (batch_job['id'], batch_job['status'], url))
            return url
        sleep_interval = (30 * (2 ** poll_attempt) +
                          (random.randint(0, 10000) / 1000))
        print 'Batch Job not ready, sleeping for %s seconds.' % sleep_interval
        sleep(sleep_interval)
        batch_job = get_batch_job(batch_job_id)
        poll_attempt += 1

    raise Exception('Batch Job not finished downloading. Try checking later.')


def get_batch_job(batch_job_id):
    batch_job_service = get_service(Services.BATCH_JOB_SERVICE)
    selector = {
      'fields': ['Id', 'Status', 'DownloadUrl'],
      'predicates': [{'field': 'Id', 'operator': 'EQUALS', 'values': 
[batch_job_id]}]
    }
    return batch_job_service.get(selector)['entries'][0]


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/cffbc088-fade-4102-8f02-8edd7d62c187%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to