2828
2929from google .ads .googleads .client import GoogleAdsClient
3030from google .ads .googleads .errors import GoogleAdsException
31- from google .ads .googleads .v19 .services .services .google_ads_service .client import GoogleAdsServiceClient
32- from google .ads .googleads .v19 .services .services .customer_service .client import CustomerServiceClient
33- from google .ads .googleads .v19 .resources .types .customer_client import CustomerClient
34- from google .ads .googleads .v19 .services .types .google_ads_service import SearchPagedResponse , GoogleAdsRow
31+ from google .ads .googleads .v20 .services .services .google_ads_service .client import (
32+ GoogleAdsServiceClient ,
33+ )
34+ from google .ads .googleads .v20 .services .services .customer_service .client import (
35+ CustomerServiceClient ,
36+ )
37+ from google .ads .googleads .v20 .resources .types .customer_client import (
38+ CustomerClient ,
39+ )
40+ from google .ads .googleads .v20 .services .types .google_ads_service import (
41+ SearchPagedResponse ,
42+ GoogleAdsRow ,
43+ )
44+
3545# ListAccessibleCustomersResponse is not directly used for a variable type,
3646# but its attribute .resource_names is used, which is List[str].
3747
38- def main (client : GoogleAdsClient , login_customer_id : Optional [str ] = None ) -> None :
48+
49+ def main (
50+ client : GoogleAdsClient , login_customer_id : Optional [str ] = None
51+ ) -> None :
3952 """Gets the account hierarchy of the given MCC and login customer ID.
4053
4154 Args:
@@ -44,10 +57,13 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
4457 method will instead list the accounts accessible from the
4558 authenticated Google Ads account.
4659 """
47-
4860 # Gets instances of the GoogleAdsService and CustomerService clients.
49- googleads_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
50- customer_service : CustomerServiceClient = client .get_service ("CustomerService" )
61+ googleads_service : GoogleAdsServiceClient = client .get_service (
62+ "GoogleAdsService"
63+ )
64+ customer_service : CustomerServiceClient = client .get_service (
65+ "CustomerService"
66+ )
5167
5268 # A collection of customer IDs to handle.
5369 seed_customer_ids : List [str ] = []
@@ -90,7 +106,9 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
90106 print (customer_id_from_parse )
91107 seed_customer_ids .append (customer_id_from_parse )
92108
93- for seed_customer_id_str in seed_customer_ids : # seed_customer_id_str is a string
109+ for (
110+ seed_customer_id_str
111+ ) in seed_customer_ids : # seed_customer_id_str is a string
94112 # Performs a breadth-first search to build a Dictionary that maps
95113 # managers to their child accounts (customerIdsToChildAccounts).
96114 # unprocessed_customer_ids should store integers.
@@ -99,16 +117,21 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
99117 root_customer_client : CustomerClient | None = None
100118
101119 while unprocessed_customer_ids :
102- customer_id_loop : int = unprocessed_customer_ids .pop (0 ) # customer_id_loop is an int
120+ customer_id_loop : int = unprocessed_customer_ids .pop (
121+ 0
122+ ) # customer_id_loop is an int
103123 # The search method expects customer_id to be a string.
104124 response : SearchPagedResponse = googleads_service .search (
105125 customer_id = str (customer_id_loop ), query = query
106126 )
107127
108128 # Iterates over all rows in all pages to get all customer
109129 # clients under the specified customer's hierarchy.
110- for googleads_row : GoogleAdsRow in response :
111- customer_client_loop_var : CustomerClient = googleads_row .customer_client
130+ googleads_row : GoogleAdsRow
131+ for googleads_row in response :
132+ customer_client_loop_var : CustomerClient = (
133+ googleads_row .customer_client
134+ )
112135
113136 # The customer client that with level 0 is the specified
114137 # customer.
@@ -134,10 +157,13 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
134157 # need to check if it's already in the Dictionary.
135158 # Assuming customer_client_loop_var.id is an int
136159 if (
137- customer_client_loop_var .id not in customer_ids_to_child_accounts
160+ customer_client_loop_var .id
161+ not in customer_ids_to_child_accounts
138162 and customer_client_loop_var .level == 1
139163 ):
140- unprocessed_customer_ids .append (customer_client_loop_var .id )
164+ unprocessed_customer_ids .append (
165+ customer_client_loop_var .id
166+ )
141167
142168 if root_customer_client is not None :
143169 print (
@@ -156,7 +182,9 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
156182
157183
158184def print_account_hierarchy (
159- customer_client : CustomerClient , customer_ids_to_child_accounts : Dict [int , List [CustomerClient ]], depth : int
185+ customer_client : CustomerClient ,
186+ customer_ids_to_child_accounts : Dict [int , List [CustomerClient ]],
187+ depth : int ,
160188) -> None :
161189 """Prints the specified account's hierarchy using recursion.
162190
@@ -182,7 +210,8 @@ def print_account_hierarchy(
182210
183211 # Recursively call this function for all child accounts of customer_client.
184212 if customer_id_print in customer_ids_to_child_accounts :
185- for child_account : CustomerClient in customer_ids_to_child_accounts [customer_id_print ]:
213+ child_account : CustomerClient
214+ for child_account in customer_ids_to_child_accounts [customer_id_print ]:
186215 print_account_hierarchy (
187216 child_account , customer_ids_to_child_accounts , depth + 1
188217 )
0 commit comments