3333import sys
3434from uuid import uuid4
3535
36+ from examples .utils .example_helpers import get_image_bytes_from_url
3637from google .ads .googleads .client import GoogleAdsClient
3738from google .ads .googleads .errors import GoogleAdsException
3839from google .ads .googleads .util import convert_snake_case_to_upper_case
3940
40- import requests
41-
4241
4342# We specify temporary IDs that are specific to a single mutate request.
4443# Temporary IDs are always negative and unique within one mutate request.
@@ -106,10 +105,12 @@ def main(client, customer_id, audience_id, brand_guidelines_enabled):
106105 client ,
107106 customer_id ,
108107 )
109- performance_max_campaign_operation = create_performance_max_campaign_operation (
110- client ,
111- customer_id ,
112- brand_guidelines_enabled ,
108+ performance_max_campaign_operation = (
109+ create_performance_max_campaign_operation (
110+ client ,
111+ customer_id ,
112+ brand_guidelines_enabled ,
113+ )
113114 )
114115 campaign_criterion_operations = create_campaign_criterion_operations (
115116 client ,
@@ -170,7 +171,9 @@ def create_campaign_budget_operation(
170171 campaign_budget .name = f"Performance Max campaign budget #{ uuid4 ()} "
171172 # The budget period already defaults to DAILY.
172173 campaign_budget .amount_micros = 50000000
173- campaign_budget .delivery_method = client .enums .BudgetDeliveryMethodEnum .STANDARD
174+ campaign_budget .delivery_method = (
175+ client .enums .BudgetDeliveryMethodEnum .STANDARD
176+ )
174177 # A Performance Max campaign cannot use a shared campaign budget.
175178 campaign_budget .explicitly_shared = False
176179
@@ -444,7 +447,9 @@ def create_asset_group_operation(
444447 for resource_name in description_asset_resource_names :
445448 mutate_operation = client .get_type ("MutateOperation" )
446449 asset_group_asset = mutate_operation .asset_group_asset_operation .create
447- asset_group_asset .field_type = client .enums .AssetFieldTypeEnum .DESCRIPTION
450+ asset_group_asset .field_type = (
451+ client .enums .AssetFieldTypeEnum .DESCRIPTION
452+ )
448453 asset_group_asset .asset_group = asset_group_service .asset_group_path (
449454 customer_id ,
450455 _ASSET_GROUP_TEMPORARY_ID ,
@@ -530,7 +535,9 @@ def create_and_link_text_asset(client, customer_id, text, field_type):
530535 customer_id ,
531536 _ASSET_GROUP_TEMPORARY_ID ,
532537 )
533- asset_group_asset .asset = asset_service .asset_path (customer_id , next_temp_id )
538+ asset_group_asset .asset = asset_service .asset_path (
539+ customer_id , next_temp_id
540+ )
534541 operations .append (mutate_operation )
535542
536543 next_temp_id -= 1
@@ -539,7 +546,9 @@ def create_and_link_text_asset(client, customer_id, text, field_type):
539546
540547
541548# [START add_performance_max_campaign_8]
542- def create_and_link_image_asset (client , customer_id , url , field_type , asset_name ):
549+ def create_and_link_image_asset (
550+ client , customer_id , url , field_type , asset_name
551+ ):
543552 """Creates a list of MutateOperations that create a new linked image asset.
544553
545554 Args:
@@ -566,7 +575,7 @@ def create_and_link_image_asset(client, customer_id, url, field_type, asset_name
566575 # name, the new name will be dropped silently.
567576 asset .name = asset_name
568577 asset .type_ = client .enums .AssetTypeEnum .IMAGE
569- asset .image_asset .data = get_image_bytes (url )
578+ asset .image_asset .data = get_image_bytes_from_url (url )
570579 operations .append (mutate_operation )
571580
572581 # Create an AssetGroupAsset to link the Asset to the AssetGroup.
@@ -577,7 +586,9 @@ def create_and_link_image_asset(client, customer_id, url, field_type, asset_name
577586 customer_id ,
578587 _ASSET_GROUP_TEMPORARY_ID ,
579588 )
580- asset_group_asset .asset = asset_service .asset_path (customer_id , next_temp_id )
589+ asset_group_asset .asset = asset_service .asset_path (
590+ customer_id , next_temp_id
591+ )
581592 operations .append (mutate_operation )
582593
583594 next_temp_id -= 1
@@ -586,7 +597,12 @@ def create_and_link_image_asset(client, customer_id, url, field_type, asset_name
586597
587598
588599def create_and_link_brand_assets (
589- client , customer_id , brand_guidelines_enabled , business_name , logo_url , logo_name
600+ client ,
601+ customer_id ,
602+ brand_guidelines_enabled ,
603+ business_name ,
604+ logo_url ,
605+ logo_name ,
590606):
591607 """Creates a list of MutateOperations that create linked brand assets.
592608
@@ -612,7 +628,9 @@ def create_and_link_brand_assets(
612628
613629 text_mutate_operation = client .get_type ("MutateOperation" )
614630 text_asset = text_mutate_operation .asset_operation .create
615- text_asset .resource_name = asset_service .asset_path (customer_id , text_asset_temp_id )
631+ text_asset .resource_name = asset_service .asset_path (
632+ customer_id , text_asset_temp_id
633+ )
616634 text_asset .text_asset .text = business_name
617635 operations .append (text_mutate_operation )
618636
@@ -630,7 +648,7 @@ def create_and_link_brand_assets(
630648 # name, the new name will be dropped silently.
631649 image_asset .name = logo_name
632650 image_asset .type_ = client .enums .AssetTypeEnum .IMAGE
633- image_asset .image_asset .data = get_image_bytes (logo_url )
651+ image_asset .image_asset .data = get_image_bytes_from_url (logo_url )
634652 operations .append (image_mutate_operation )
635653
636654 if brand_guidelines_enabled :
@@ -653,7 +671,9 @@ def create_and_link_brand_assets(
653671 operations .append (business_name_mutate_operation )
654672
655673 logo_mutate_operation = client .get_type ("MutateOperation" )
656- logo_campaign_asset = logo_mutate_operation .campaign_asset_operation .create
674+ logo_campaign_asset = (
675+ logo_mutate_operation .campaign_asset_operation .create
676+ )
657677 logo_campaign_asset .field_type = client .enums .AssetFieldTypeEnum .LOGO
658678 logo_campaign_asset .campaign = campaign_service .campaign_path (
659679 customer_id , _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID
@@ -690,9 +710,11 @@ def create_and_link_brand_assets(
690710 logo_mutate_operation .asset_group_asset_operation .create
691711 )
692712 logo_asset_group_asset .field_type = client .enums .AssetFieldTypeEnum .LOGO
693- logo_asset_group_asset .asset_group = asset_group_service .asset_group_path (
694- customer_id ,
695- _ASSET_GROUP_TEMPORARY_ID ,
713+ logo_asset_group_asset .asset_group = (
714+ asset_group_service .asset_group_path (
715+ customer_id ,
716+ _ASSET_GROUP_TEMPORARY_ID ,
717+ )
696718 )
697719 logo_asset_group_asset .asset = asset_service .asset_path (
698720 customer_id , image_asset_temp_id
@@ -702,19 +724,6 @@ def create_and_link_brand_assets(
702724 return operations
703725
704726
705- def get_image_bytes (url ):
706- """Loads image data from a URL.
707-
708- Args:
709- url: a URL str.
710-
711- Returns:
712- Images bytes loaded from the given URL.
713- """
714- response = requests .get (url )
715- return response .content
716-
717-
718727def print_response_details (response ):
719728 """Prints the details of a MutateGoogleAdsResponse.
720729
0 commit comments