Beispiel #1
0
    def add_operation(self,
                      campaign_id,
                      bid,
                      status="ENABLED",
                      adgroup_id=None,
                      label_id=None):
        """ Operation to add a new adgroup """
        _, micro_max_cpc = AdWordsService.reg_and_micro(bid)

        operation = {
            "xsi_type": "AdGroupOperation",
            "operator": "ADD",
            "operand": {
                "campaignId": campaign_id,
                "name": self.name,
                "status": status,
                "biddingStrategyConfiguration": {
                    "bids": [{
                        "xsi_type": "CpcBid",
                        "bid": {
                            "microAmount": micro_max_cpc
                        }
                    }]
                }
            }
        }
        if adgroup_id is not None:
            operation["operand"]["id"] = adgroup_id

        if label_id is not None:
            operation["operand"]["labels"] = [{"id": label_id}]
        return operation
Beispiel #2
0
    def set_bid(adgroup_id, keyword_id, bid):
        _, micro_max_cpc = AdWordsService.reg_and_micro(bid)

        operation = {
            "xsi_type": "AdGroupCriterionOperation",
            "operator": "SET",
            "operand": {
                "xsi_type": "BiddableAdGroupCriterion",
                "adGroupId": adgroup_id,
                "criterion": {
                    "xsi_type": "Keyword",
                    "id": keyword_id,
                },
                "biddingStrategyConfiguration": {
                    "bids": [{
                        "xsi_type": "CpcBid",
                        "bid": {
                            "xsi_type": "Money",
                            "microAmount": micro_max_cpc
                        }
                    }]
                }
            }
        }
        return operation
Beispiel #3
0
    def __init__(self, text, match_type, bid, final_url, https=True):
        self.text = text.lower()
        self.match_type = match_type.upper()
        self.max_cpc, self.micro_max_cpc = AdWordsService.reg_and_micro(bid)
        if isinstance(final_url, str):
            self.final_url = FinalUrl(final_url, https=https)
        elif isinstance(final_url, FinalUrl):
            self.final_url = final_url

        self.basic_checks()
Beispiel #4
0
    def set_bid_operation(adgroup_id, bid):
        """ Operation to change the bid of an AdGroup """
        _, micro_max_cpc = AdWordsService.reg_and_micro(bid)

        operation = {
            "xsi_type": "AdGroupOperation",
            "operator": "SET",
            "operand": {
                "id": adgroup_id,
                "biddingStrategyConfiguration": {
                    "bids": [{
                        "xsi_type": "CpcBid",
                        "bid": {
                            "microAmount": micro_max_cpc
                        }
                    }]
                }
            }
        }
        return operation
Beispiel #5
0
def micro_to_float(micro_amount, default_value=-1.00):
    """ Convert micro amounts to regular euro with default value if unexpected value occurs """
    try:
        return AdWordsService.micro_to_reg(micro_amount)
    except ValueError:
        return default_value
Beispiel #6
0
import os
from freedan.adwords_services.adwords_service import AdWordsService

test_dir = os.path.dirname(__file__)
adwords_test_credentials = os.path.join(test_dir,
                                        "adwords_test_credentials.yaml")
adwords_service = AdWordsService(adwords_test_credentials)

adgroup1_name = "Ad Group #1"
adgroup1_id = 47391167467


def service_suds_client(service_name):
    service = adwords_service.init_service(service_name)
    return service.suds_client


no_error_stdout = "\nAmount of operations: 1\n##### OperationUpload is LIVE: False. #####\n\n"
Beispiel #7
0
 def __init__(self, amount, is_shared=False, name=None):
     self.amount, self.micro_amount = AdWordsService.reg_and_micro(amount)
     self.name = name or 'API Budget #{uuid}'.format(uuid=uuid.uuid4().int)
     self.is_shared = is_shared