Skip to content

Commit 306c6a6

Browse files
authored
Add annotations to the google ads account analyzer example (#947)
1 parent e55d98a commit 306c6a6

5 files changed

Lines changed: 27 additions & 20 deletions

File tree

examples/google-ads-account-analyzer-demo/analyzer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
import argparse
1919
import sys
20+
from typing import Optional, Dict, List, Any
2021

2122
from google.ads.googleads.client import GoogleAdsClient
2223
from google.ads.googleads.errors import GoogleAdsException
2324

2425
_DEFAULT_LOG_SPACE_LENGTH = 4
2526

2627

27-
def account_hierarchy_module(google_ads_client, customer_id):
28+
def account_hierarchy_module(google_ads_client: GoogleAdsClient, customer_id: Optional[str]):
2829
"""Print the account hierarchy for the given login customer ID.
2930
3031
Args:
@@ -74,7 +75,7 @@ def account_hierarchy_module(google_ads_client, customer_id):
7475
# Performs a breadth-first search to build a Dictionary that maps
7576
# managers to their child accounts (customer_ids_to_child_accounts).
7677
unprocessed_customer_ids = [seed_customer_id]
77-
customer_ids_to_child_accounts = dict()
78+
customer_ids_to_child_accounts: Dict[str, List[Any]] = dict()
7879
root_customer_client = None
7980

8081
while unprocessed_customer_ids:
@@ -129,7 +130,7 @@ def account_hierarchy_module(google_ads_client, customer_id):
129130

130131

131132
def print_account_hierarchy(
132-
customer_client, customer_ids_to_child_accounts, depth
133+
customer_client: Any, customer_ids_to_child_accounts: Dict[str, List[Any]], depth: int
133134
):
134135
"""Prints the specified account's hierarchy using recursion.
135136
@@ -157,7 +158,7 @@ def print_account_hierarchy(
157158
)
158159

159160

160-
def get_users_module(google_ads_client, customer_id):
161+
def get_users_module(google_ads_client: GoogleAdsClient, customer_id: Optional[str]):
161162
"""Prints the user access information for the given customer_id.
162163
163164
Args:

examples/misc/add_ad_group_image_asset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def main(
5050

5151
for result in response.results:
5252
print(
53-
"Created ad group asset with resource name: "
54-
f"'{result.resource_name}'"
53+
f"Created ad group asset with resource name: '{result.resource_name}'"
5554
)
5655

5756

examples/misc/campaign_report_to_csv.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"""
2929
import argparse
3030
import csv
31-
import sys
3231
import os
32+
import sys
3333

3434
from google.ads.googleads.client import GoogleAdsClient
3535
from google.ads.googleads.errors import GoogleAdsException
@@ -119,26 +119,32 @@ def main(
119119
"--customer_id",
120120
type=str,
121121
required=True,
122-
help="The Google Ads customer ID of the account you would like to get "
123-
"the report for to write to CSV.",
122+
help=(
123+
"The Google Ads customer ID of the account you would like to get "
124+
"the report for to write to CSV."
125+
),
124126
)
125127
parser.add_argument(
126128
"-o",
127129
"--output_file",
128130
type=str,
129131
required=False,
130132
default=_DEFAULT_FILE_NAME,
131-
help="Name of the local CSV file to save the report to. File will be "
132-
"saved in the same directory as the script.",
133+
help=(
134+
"Name of the local CSV file to save the report to. File will be "
135+
"saved in the same directory as the script."
136+
),
133137
)
134138
# Optional boolean argument for writing headers.
135139
parser.add_argument(
136140
"-w",
137141
"--write_headers",
138142
action="store_true",
139-
help="Writes headers to the CSV file if argument is supplied. Simply "
140-
"add -w if you want the headers defined in the script to be "
141-
"added as the first row in the CSV file.",
143+
help=(
144+
"Writes headers to the CSV file if argument is supplied. Simply "
145+
"add -w if you want the headers defined in the script to be "
146+
"added as the first row in the CSV file."
147+
),
142148
)
143149
args = parser.parse_args()
144150

examples/misc/set_custom_client_timeouts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ def make_unary_call(client: GoogleAdsClient, customer_id: str) -> None:
158158

159159
if __name__ == "__main__":
160160
parser = argparse.ArgumentParser(
161-
description="Demonstrates custom client timeouts in the context of "
162-
"server streaming and unary calls."
161+
description=(
162+
"Demonstrates custom client timeouts in the context of "
163+
"server streaming and unary calls."
164+
)
163165
)
164166
# The following argument(s) should be provided to run the example.
165167
parser.add_argument(

examples/misc/upload_image_asset.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import argparse
2222
import sys
2323

24+
from examples.utils.example_helpers import get_image_bytes_from_url
2425
from google.ads.googleads.client import GoogleAdsClient
2526
from google.ads.googleads.errors import GoogleAdsException
2627
from google.ads.googleads.v19.services.types import (
@@ -54,10 +55,8 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
5455
# When there is an existing image asset with the same content but a different
5556
# name, the new name will be dropped silently.
5657
asset.name = "Marketing Image"
57-
mutate_asset_response: MutateAssetsResponse = (
58-
asset_service.mutate_assets(
59-
customer_id=customer_id, operations=[asset_operation]
60-
)
58+
mutate_asset_response: MutateAssetsResponse = asset_service.mutate_assets(
59+
customer_id=customer_id, operations=[asset_operation]
6160
)
6261
print("Uploaded file(s):")
6362
for row in mutate_asset_response.results:

0 commit comments

Comments
 (0)