Skip to content

Commit 038c96f

Browse files
authored
Changes for release v5_0. (googleads#299)
1 parent f63e318 commit 038c96f

1,645 files changed

Lines changed: 224973 additions & 4737 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,31 @@ information on using pull requests.
2626

2727
This project follows [Google's Open Source Community
2828
Guidelines](https://opensource.google.com/conduct/).
29+
30+
## Code Style
31+
32+
This library conforms to [PEP 8](https://www.python.org/dev/peps/pep-0008/)
33+
style guidelines and enforces an 80 character line width. It's recommended
34+
that any contributor run the auto-formatter [`black`](https://github.com/psf/black),
35+
version 19.10b0 on the non-generated codebase whenever making changes. To get
36+
started, first install the appropriate version of `black`:
37+
38+
```
39+
python -m pip install black==19.10b0
40+
```
41+
42+
You can manually run the formatter on all non-generated code with the following
43+
command:
44+
45+
```
46+
python -m black -l 80 -t py37 --exclude "/(v[0-9]+|\.eggs|\.git|_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist)/" .
47+
```
48+
49+
Alternatively, if you intend to contribute regularly, it might be easier to
50+
append this script to the `.git/hooks/pre-commit` file:
51+
52+
```
53+
FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.py" | grep -v "google/ads/google_ads/v.*")
54+
echo "${FILES}" | xargs python -m black -l 80 -t py37
55+
echo "${FILES}" | xargs git add
56+
```

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* 7.0.0
2+
- Google Ads v5_0 release
3+
- Updates to examples to support addition of field presence on certain
4+
resources, changing from accessing wrapper types to accessing primitives.
5+
16
* 6.0.0
27
- Google Ads v4_0 release
38
- Deprecate v1_0

examples/account_management/create_customer.py

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,68 @@
2929

3030

3131
def main(client, manager_customer_id):
32-
customer_service = client.get_service('CustomerService', version='v4')
33-
customer = client.get_type('Customer', version='v4')
34-
today = datetime.today().strftime('%Y%m%d %H:%M:%S')
35-
customer.descriptive_name.value = ('Account created with '
36-
'CustomerService on %s' % today)
32+
customer_service = client.get_service("CustomerService", version="v5")
33+
customer = client.get_type("Customer", version="v5")
34+
today = datetime.today().strftime("%Y%m%d %H:%M:%S")
35+
customer.descriptive_name = (
36+
"Account created with " "CustomerService on %s" % today
37+
)
3738
# For a list of valid currency codes and time zones see this documentation:
3839
# https://developers.google.com/adwords/api/docs/appendix/codes-formats
39-
customer.currency_code.value = 'USD'
40-
customer.time_zone.value = 'America/New_York'
40+
customer.currency_code = "USD"
41+
customer.time_zone = "America/New_York"
4142
# The below values are optional. For more information about URL
4243
# options see: https://support.google.com/google-ads/answer/6305348
43-
customer.tracking_url_template.value = '{lpurl}?device={device}'
44-
customer.final_url_suffix.value = ('keyword={keyword}&matchtype={matchtype}'
45-
'&adgroupid={adgroupid}')
46-
customer.has_partners_badge.value = False
44+
customer.tracking_url_template = "{lpurl}?device={device}"
45+
customer.final_url_suffix = (
46+
"keyword={keyword}&matchtype={matchtype}" "&adgroupid={adgroupid}"
47+
)
48+
customer.has_partners_badge = False
4749

4850
try:
4951
response = customer_service.create_customer_client(
50-
manager_customer_id, customer)
51-
print(('Customer created with resource name "%s" under manager account '
52-
'with customer ID "%s"') %
53-
(response.resource_name, manager_customer_id))
52+
manager_customer_id, customer
53+
)
54+
print(
55+
(
56+
'Customer created with resource name "%s" under manager account '
57+
'with customer ID "%s"'
58+
)
59+
% (response.resource_name, manager_customer_id)
60+
)
5461
except google.ads.google_ads.errors.GoogleAdsException as ex:
55-
print('Request with ID "%s" failed with status "%s" and includes the '
56-
'following errors:' % (ex.request_id, ex.error.code().name))
62+
print(
63+
'Request with ID "%s" failed with status "%s" and includes the '
64+
"following errors:" % (ex.request_id, ex.error.code().name)
65+
)
5766
for error in ex.failure.errors:
5867
print('\tError with message "%s".' % error.message)
5968
if error.location:
6069
for field_path_element in error.location.field_path_elements:
61-
print('\t\tOn field: %s' % field_path_element.field_name)
70+
print("\t\tOn field: %s" % field_path_element.field_name)
6271
sys.exit(1)
6372

6473

65-
if __name__ == '__main__':
74+
if __name__ == "__main__":
6675
# GoogleAdsClient will read the google-ads.yaml configuration file in the
6776
# home directory if none is specified.
68-
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
69-
.load_from_storage())
77+
google_ads_client = (
78+
google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
79+
)
7080

7181
parser = argparse.ArgumentParser(
72-
description=('Creates a new client under the given manager.'))
82+
description=("Creates a new client under the given manager.")
83+
)
7384
# The following argument(s) should be provided to run the example.
74-
parser.add_argument('-m', '--manager_customer_id', type=str,
75-
required=True, help='A Google Ads customer ID for the '
76-
'manager account under which the new customer will '
77-
'be created.')
85+
parser.add_argument(
86+
"-m",
87+
"--manager_customer_id",
88+
type=str,
89+
required=True,
90+
help="A Google Ads customer ID for the "
91+
"manager account under which the new customer will "
92+
"be created.",
93+
)
7894
args = parser.parse_args()
7995

8096
main(google_ads_client, args.manager_customer_id)

examples/account_management/get_account_changes.py

Lines changed: 96 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -28,91 +28,113 @@
2828

2929

3030
def resource_name_for_resource_type(resource_type, row):
31-
"""Return the resource name for the resource type.
31+
"""Return the resource name for the resource type.
3232
3333
Each returned row contains all possible changed fields. This function
3434
returns the resource name of the changed field based on the
3535
resource type. The changed field's parent is also populated but is not used.
36-
36+
3737
Args:
3838
resource_type: the string equivalent of the resource type
3939
row: a single row returned from the service
4040
4141
Returns:
4242
The resource name of the field that changed.
4343
"""
44-
resource_name = '' # default for UNSPECIFIED or UNKNOWN
45-
if resource_type == 'AD_GROUP':
46-
resource_name = row.change_status.ad_group.value
47-
elif resource_type == 'AD_GROUP_AD':
48-
resource_name = row.change_status.ad_group_ad.value
49-
elif resource_type == 'AD_GROUP_CRITERION':
50-
resource_name = row.change_status.ad_group_criterion.value
51-
elif resource_type == 'CAMPAIGN':
52-
resource_name = row.change_status.campaign.value
53-
elif resource_type == 'CAMPAIGN_CRITERION':
54-
resource_name = row.change_status.campaign_criterion.value
55-
return resource_name
44+
resource_name = "" # default for UNSPECIFIED or UNKNOWN
45+
if resource_type == "AD_GROUP":
46+
resource_name = row.change_status.ad_group
47+
elif resource_type == "AD_GROUP_AD":
48+
resource_name = row.change_status.ad_group_ad
49+
elif resource_type == "AD_GROUP_CRITERION":
50+
resource_name = row.change_status.ad_group_criterion
51+
elif resource_type == "CAMPAIGN":
52+
resource_name = row.change_status.campaign
53+
elif resource_type == "CAMPAIGN_CRITERION":
54+
resource_name = row.change_status.campaign_criterion
55+
return resource_name
5656

5757

5858
def main(client, customer_id):
59-
ads_service = client.get_service('GoogleAdsService', version='v4')
60-
query = ('SELECT change_status.resource_name, '
61-
'change_status.last_change_date_time, '
62-
'change_status.resource_type, '
63-
'change_status.campaign, '
64-
'change_status.ad_group, '
65-
'change_status.resource_status, '
66-
'change_status.ad_group_ad, '
67-
'change_status.ad_group_criterion, '
68-
'change_status.campaign_criterion '
69-
'FROM change_status '
70-
'WHERE change_status.last_change_date_time DURING LAST_7_DAYS '
71-
'ORDER BY change_status.last_change_date_time')
72-
73-
response = ads_service.search(customer_id, query=query,
74-
page_size=ADS_PAGE_SIZE)
75-
76-
resource_type_enum = (client.get_type(
77-
'ChangeStatusResourceTypeEnum', version='v4').ChangeStatusResourceType)
78-
change_status_operation_enum = (client.get_type(
79-
'ChangeStatusOperationEnum', version='v4').ChangeStatusOperation)
80-
81-
try:
82-
for row in response:
83-
resource_type = (resource_type_enum.Name(row.change_status
84-
.resource_type))
85-
resource_status = (change_status_operation_enum
86-
.Name(row.change_status.resource_status))
87-
print ('On "%s", change status "%s" shows a resource type of "%s" '
88-
'with resource name "%s" was "%s".'
89-
% (row.change_status.last_change_date_time.value,
90-
row.change_status.resource_name,
91-
resource_type,
92-
resource_name_for_resource_type(resource_type, row),
93-
resource_status))
94-
except google.ads.google_ads.errors.GoogleAdsException as ex:
95-
print('Request with ID "%s" failed with status "%s" and includes the '
96-
'following errors:' % (ex.request_id, ex.error.code().name))
97-
for error in ex.failure.errors:
98-
print('\tError with message "%s".' % error.message)
99-
if error.location:
100-
for field_path_element in error.location.field_path_elements:
101-
print('\t\tOn field: %s' % field_path_element.field_name)
102-
sys.exit(1)
103-
104-
105-
if __name__ == '__main__':
106-
# GoogleAdsClient will read a google-ads.yaml configuration file in the
107-
# home directory if none is specified.
108-
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
109-
.load_from_storage())
110-
111-
parser = argparse.ArgumentParser(
112-
description=('Displays account changes that occurred in the last 7 days.'))
113-
# The following argument(s) should be provided to run the example.
114-
parser.add_argument('-c', '--customer_id', type=str,
115-
required=True, help='The Google Ads customer ID.')
116-
args = parser.parse_args()
117-
118-
main(google_ads_client, args.customer_id)
59+
ads_service = client.get_service("GoogleAdsService", version="v5")
60+
query = (
61+
"SELECT change_status.resource_name, "
62+
"change_status.last_change_date_time, "
63+
"change_status.resource_type, "
64+
"change_status.campaign, "
65+
"change_status.ad_group, "
66+
"change_status.resource_status, "
67+
"change_status.ad_group_ad, "
68+
"change_status.ad_group_criterion, "
69+
"change_status.campaign_criterion "
70+
"FROM change_status "
71+
"WHERE change_status.last_change_date_time DURING LAST_7_DAYS "
72+
"ORDER BY change_status.last_change_date_time"
73+
)
74+
75+
response = ads_service.search(
76+
customer_id, query=query, page_size=ADS_PAGE_SIZE
77+
)
78+
79+
resource_type_enum = client.get_type(
80+
"ChangeStatusResourceTypeEnum", version="v5"
81+
).ChangeStatusResourceType
82+
change_status_operation_enum = client.get_type(
83+
"ChangeStatusOperationEnum", version="v5"
84+
).ChangeStatusOperation
85+
86+
try:
87+
for row in response:
88+
resource_type = resource_type_enum.Name(
89+
row.change_status.resource_type
90+
)
91+
resource_status = change_status_operation_enum.Name(
92+
row.change_status.resource_status
93+
)
94+
print(
95+
'On "%s", change status "%s" shows a resource type of "%s" '
96+
'with resource name "%s" was "%s".'
97+
% (
98+
row.change_status.last_change_date_time.value,
99+
row.change_status.resource_name,
100+
resource_type,
101+
resource_name_for_resource_type(resource_type, row),
102+
resource_status,
103+
)
104+
)
105+
except google.ads.google_ads.errors.GoogleAdsException as ex:
106+
print(
107+
'Request with ID "%s" failed with status "%s" and includes the '
108+
"following errors:" % (ex.request_id, ex.error.code().name)
109+
)
110+
for error in ex.failure.errors:
111+
print('\tError with message "%s".' % error.message)
112+
if error.location:
113+
for field_path_element in error.location.field_path_elements:
114+
print("\t\tOn field: %s" % field_path_element.field_name)
115+
sys.exit(1)
116+
117+
118+
if __name__ == "__main__":
119+
# GoogleAdsClient will read a google-ads.yaml configuration file in the
120+
# home directory if none is specified.
121+
google_ads_client = (
122+
google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
123+
)
124+
125+
parser = argparse.ArgumentParser(
126+
description=(
127+
"Displays account changes that occurred in the last 7 days."
128+
)
129+
)
130+
# The following argument(s) should be provided to run the example.
131+
parser.add_argument(
132+
"-c",
133+
"--customer_id",
134+
type=str,
135+
required=True,
136+
help="The Google Ads customer ID.",
137+
)
138+
args = parser.parse_args()
139+
140+
main(google_ads_client, args.customer_id)

0 commit comments

Comments
 (0)