def add_adgroup_using_batch_job(path_credentials, is_debug):
    """
    A script that will add an adgroup with keywords and ads using batch upload.

    :param path_credentials: str, path to your adwords credentials file
    :param is_debug: bool
    """
    adwords_service = freedan.AdWordsService(path_credentials)
    for account in adwords_service.accounts():
        print(account)

        # define new adwords instances
        adgroup = AdGroup(name="test_adgroup_1")
        keyword1 = Keyword(text="asofjna",
                           match_type="EXACT",
                           bid=1.0,
                           final_url="https://aiosjda.de")
        keyword2 = Keyword(text="asofjna",
                           match_type="PHRASE",
                           bid=0.5,
                           final_url="https://aiosjda.de")
        ad1 = ExtendedTextAd(headline1="yo",
                             headline2="yoyo",
                             description="dem boys",
                             path1="Yo",
                             path2="Dude",
                             final_url="https://aiosjda.de")
        ad2 = ExtendedTextAd(headline1="yo",
                             headline2="yoyo",
                             description="dem boyoyoyoys",
                             path1="Yo",
                             path2="Dude",
                             final_url="https://aiosjda.de")

        # determine temporary id for adgroup
        temp_id_helper = freedan.TempIdHelper()
        adgroup_id = temp_id_helper.temp_id

        # operations
        adgroup_operations = [
            adgroup.add_operation(campaign_id=CAMPAIGN_ID,
                                  bid=0.01,
                                  adgroup_id=adgroup_id)
        ]
        keyword_operations = [
            keyword1.add_operation(adgroup_id=adgroup_id),
            keyword2.add_operation(adgroup_id=adgroup_id)
        ]
        ad_operations = [
            ad1.add_operation(adgroup_id=adgroup_id),
            ad2.add_operation(adgroup_id=adgroup_id)
        ]

        # upload
        operations = (adgroup_operations, keyword_operations, ad_operations)
        adwords_service.upload(operations, is_debug=is_debug, method="batch")
Пример #2
0
def add_adgroup_using_batch_job(path_credentials, is_debug):
    """
    A script that will add an adgroup with keywords and ads using batch upload.

    :param path_credentials: str, path to your adwords credentials file
    :param is_debug: bool
    """
    adwords_service = freedan.AdWordsService(path_credentials)
    for account in adwords_service.accounts():
        print(account)

        # define new adwords instances.
        # of course you can add multiple adgroups per campaign and multiple keywords/ads per adgroup.
        # check out add_adgroup_using_batch_job.py for more details
        budget = CampaignBudget(amount=10)
        campaign = Campaign(name="test_campaign_1")
        adgroup = AdGroup(name="test_adgroup_1")
        keyword = Keyword(text="asofjna",
                          match_type="EXACT",
                          bid=1.0,
                          final_url="https://aiosjda.de")
        ad = ExtendedTextAd(headline1="yo",
                            headline2="yoyo",
                            description="dem boys",
                            path1="Yo",
                            path2="Dude",
                            final_url="https://aiosjda.de")

        # determine temporary ids for batch upload
        # magic: those ids are different from another ;)
        temp_id_helper = freedan.TempIdHelper()
        budget_id = temp_id_helper.temp_id
        campaign_id = temp_id_helper.temp_id
        adgroup_id = temp_id_helper.temp_id

        # operations
        budget_operations = [budget.add_operation(temp_id=budget_id)]
        campaign_operations = [
            campaign.add_operation(budget_id=budget_id,
                                   campaign_id=campaign_id)
        ]
        # you might need additional operations for device, language or location targetings based on your business logic

        adgroup_operations = [
            adgroup.add_operation(campaign_id=campaign_id,
                                  bid=0.01,
                                  adgroup_id=adgroup_id)
        ]
        keyword_operations = [keyword.add_operation(adgroup_id=adgroup_id)]
        ad_operations = [ad.add_operation(adgroup_id=adgroup_id)]

        # upload
        operations = (budget_operations, campaign_operations,
                      adgroup_operations, keyword_operations, ad_operations)
        adwords_service.upload(operations, is_debug=is_debug, method="batch")
Пример #3
0
def build_operations(adgroups):
    """ Build delete operations for AdGroups
    :param adgroups: DataFrame
    :return: list of operations
    """
    operations = list()
    for index, row in adgroups.iterrows():
        adgroup_id = int(row["AdGroupId"])
        delete_operation = AdGroup.delete_operation(adgroup_id=adgroup_id)
        operations.append(delete_operation)
    return operations
Пример #4
0
def test_too_many_operations_in_standard_upload():
    from tests import adwords_service, adgroup1_name, adgroup1_id
    from freedan import AdGroup

    correct_operations = [
        AdGroup.set_name_operation(adgroup_id=adgroup1_id,
                                   new_name=adgroup1_name)
    ]

    # too many operations for standard upload
    too_many_operations = correct_operations * 5001
    with pytest.raises(IOError):
        adwords_service.upload(too_many_operations,
                               is_debug=True,
                               method="standard")
Пример #5
0
def test_flawed_upload():
    from tests import adwords_service, adgroup1_name, adgroup1_id
    from freedan import AdGroup

    flawed_operations = [
        AdGroup.set_name_operation(adgroup_id=adgroup1_id + 1,
                                   new_name=adgroup1_name)
    ]

    adwords_service.upload(flawed_operations, is_debug=True, method="standard")
    adwords_service.upload(flawed_operations,
                           is_debug=True,
                           method="batch",
                           report_on_results=True)
    adwords_service.upload(flawed_operations,
                           is_debug=False,
                           method="standard")
Пример #6
0
def test_different_operation_types_in_standard_upload():
    from tests import adwords_service, adgroup1_name, adgroup1_id
    from freedan import AdGroup, Label

    # this test scenario is particularly interesting since both use the AdGroupService for upload.
    # but they use mutate and mutateLabel in the actual mutate call
    # so an error must be raised
    ag_label = Label("ag_label_test")
    ag_label.update_id(adwords_service,
                       action_if_not_found="create",
                       is_debug=True)
    correct_operations = [
        AdGroup.set_name_operation(adgroup_id=adgroup1_id,
                                   new_name=adgroup1_name),
        ag_label.apply_on_adgroup_operation(adgroup_id=adgroup1_id)
    ]

    with pytest.raises(IOError):
        adwords_service.upload(correct_operations,
                               is_debug=True,
                               method="standard")
Пример #7
0
def test_good_upload():
    from tests import adwords_service, adgroup1_name, adgroup1_id
    from freedan import AdGroup

    correct_operations = [
        AdGroup.set_name_operation(adgroup_id=adgroup1_id,
                                   new_name=adgroup1_name)
    ]

    adwords_service.upload(correct_operations,
                           is_debug=True,
                           method="standard")
    adwords_service.upload(correct_operations, is_debug=True, method="batch")
    adwords_service.upload(correct_operations,
                           is_debug=False,
                           method="standard")
    adwords_service.upload(correct_operations,
                           is_debug=False,
                           method="batch",
                           report_on_results=False,
                           batch_sleep_interval=2)