Esempio n. 1
0
def _adjust_bids():
    client = AdWords(workdir='./tests/generated_files')

    for keyword in _get_keywords_report(client):
        entry = {
            'object_type': 'keyword',
            'cpc_bid': 4.20,
            'client_id': keyword['ExternalCustomerId'],
            'campaign_id': keyword['CampaignId'],
            'adgroup_id': keyword['AdGroupId'],
            'criteria_id': keyword['Id'],
            'operator': 'SET',
        }
        client.insert(entry)

    for adgroup in _get_adgroups_report(client):
        entry = {
            'object_type': 'adgroup',
            'cpc_bid': 4.20,
            'client_id': adgroup['ExternalCustomerId'],
            'campaign_id': adgroup['CampaignId'],
            'adgroup_id': adgroup['AdGroupId'],
            'operator': 'SET',
        }
        client.insert(entry)

    operations_folder = client.split()
    client.execute_operations(operations_folder)
    return client.wait_jobs(operations_folder)
Esempio n. 2
0
def _get_adgroups_report(client=None):
    client = client or AdWords()
    report_df = reports.get_adgroups_report(client,
                                            7857288943,
                                            'CampaignStatus = "PAUSED"',
                                            fields=True)
    return report_df
Esempio n. 3
0
def _delete_campaigns():
    client = AdWords(workdir='./tests/generated_files')
    new_report_df = reports.get_campaigns_report(client, 7857288943, 'CampaignStatus != "REMOVED"', fields=True)
    for campaign in new_report_df:
        entry = {
            'object_type': 'campaign',
            'client_id': 7857288943,
            'campaign_id': campaign['CampaignId'],
            'campaign_name': 'API test campaign',
            'operator': 'SET',
            'status': 'REMOVED',
        }
        client.insert(entry)
    operations_folder = client.split()
    client.execute_operations(operations_folder)
    return client.wait_jobs(operations_folder)
Esempio n. 4
0
def _create_campaign():
    client = AdWords(workdir='./tests/generated_files')
    client.insert({
        'object_type': 'campaign',
        'client_id': 7857288943,
        'campaign_id': -1,
        'budget': 1000,
        'campaign_name': 'API test campaign',
        'locations': [1001773, 1001768],  # Sao Paulo, Sao Caetano
        'languages': [1014, 1000],  # Portuguese, English
        'status': 'PAUSED',
    })
    client.insert({
        'object_type': 'adgroup',
        'client_id': 7857288943,
        'campaign_id': -1,
        'adgroup_id': -2,
        'adgroup_name': 'API test adgroup',
        'cpc_bid': 13.37,
    })
    client.insert({
        'object_type': 'keyword',
        'client_id': 7857288943,
        'campaign_id': -1,
        'adgroup_id': -2,
        'text': 'my search term',
        'keyword_match_type': 'broad',
        'status': 'PAUSED',
        'cpc_bid': 13.37,
    })
    client.insert({
        'object_type': 'ad',
        'client_id': 7857288943,
        'campaign_id': -1,
        'adgroup_id': -2,
        'headline_part_1': 'Ad test',
        'headline_part_2': 'my pretty test',
        'description': 'This is my test ad',
        'path_1': 'test',
        'path_2': 'ad',
        'final_urls': 'http://www.mytest.com/',
        'final_mobile_urls': 'http://m.mytest.com/',
    })
    operations_folder = client.split()
    client.execute_operations(operations_folder)
    return client.wait_jobs(operations_folder)
Esempio n. 5
0
def _sync_operations():
    client = AdWords()

    get_internal_operation = {
        'object_type':
        'shared_set',
        'client_id':
        7857288943,
        'fields': ['Name', 'SharedSetId', 'Type', 'Status'],
        'predicates': [
            ('Name', 'EQUALS', 'API Sync Test'),
            ('Status', 'EQUALS', 'ENABLED'),
        ]
    }
    shared_sets = client.get_entities(get_internal_operation)
    for shared_set in shared_sets:
        client.insert({
            'object_type': 'shared_set',
            'client_id': 7857288943,
            'shared_set_id': shared_set['sharedSetId'],
            'operator': 'REMOVE'
        })

    client.execute_operations(sync=True)

    client.insert({
        'object_type': 'shared_set',
        'client_id': 7857288943,
        'shared_set_name': 'API Sync Test',
        'shared_set_type': 'NEGATIVE_KEYWORDS',
    })

    client.execute_operations(sync=True)

    shared_sets = client.get_entities(get_internal_operation)

    for shared_set in shared_sets:
        client.insert({
            'object_type': 'shared_set',
            'client_id': 7857288943,
            'shared_set_id': shared_set['sharedSetId'],
            'operator': 'REMOVE'
        })

    client.execute_operations(sync=True)
Esempio n. 6
0
def test_batchjobs():
    client = AdWords()
    list(client.get_batchjobs())
Esempio n. 7
0
def test_get_accounts():
    client = AdWords()
    client.get_accounts()