Skip to content

Commit a47cc5a

Browse files
committed
Update annotations PR for basic_operations
1 parent 0d79fb1 commit a47cc5a

File tree

10 files changed

+74
-59
lines changed

10 files changed

+74
-59
lines changed

examples/basic_operations/add_ad_groups.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020

2121
import argparse
2222
import sys
23+
from typing import List
2324
import uuid
24-
from typing import Any, MutableSequence
2525

2626
from google.ads.googleads.client import GoogleAdsClient
2727
from google.ads.googleads.errors import GoogleAdsException
28-
from google.ads.googleads.v19.services.types.ad_group_service import (
28+
from google.ads.googleads.v20.services.types.ad_group_service import (
2929
AdGroupOperation,
3030
MutateAdGroupsResponse,
3131
AdGroupServiceClient,
3232
)
33-
from google.ads.googleads.v19.services.types.campaign_service import (
33+
from google.ads.googleads.v20.services.types.campaign_service import (
3434
CampaignServiceClient,
3535
)
36-
from google.ads.googleads.v19.resources.types.ad_group import AdGroup
36+
from google.ads.googleads.v20.resources.types.ad_group import AdGroup
3737

3838

3939
def main(
@@ -55,11 +55,13 @@ def main(
5555
ad_group.type_ = client.enums.AdGroupTypeEnum.SEARCH_STANDARD
5656
ad_group.cpc_bid_micros = 10000000
5757

58+
operations: List[AdGroupOperation] = [ad_group_operation]
59+
5860
# Add the ad group.
5961
ad_group_response: MutateAdGroupsResponse = (
6062
ad_group_service.mutate_ad_groups(
6163
customer_id=customer_id,
62-
operations=[ad_group_operation], # type: ignore
64+
operations=operations,
6365
)
6466
)
6567
print(f"Created ad group {ad_group_response.results[0].resource_name}.")

examples/basic_operations/add_campaigns.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,29 @@
1818
"""
1919

2020

21-
import argparse
2221
import argparse
2322
import datetime
2423
import sys
24+
from typing import List
2525
import uuid
26-
from typing import MutableSequence
2726

2827
from google.ads.googleads.client import GoogleAdsClient
2928
from google.ads.googleads.errors import GoogleAdsException
30-
from google.ads.googleads.v19.services.types.campaign_budget_service import (
29+
from google.ads.googleads.v20.services.types.campaign_budget_service import (
3130
CampaignBudgetOperation,
3231
CampaignBudgetServiceClient,
3332
MutateCampaignBudgetsResponse,
3433
)
35-
from google.ads.googleads.v19.services.types.campaign_service import (
34+
from google.ads.googleads.v20.services.types.campaign_service import (
3635
CampaignOperation,
3736
CampaignServiceClient,
3837
MutateCampaignsResponse,
3938
)
40-
from google.ads.googleads.v19.resources.types.campaign_budget import (
39+
from google.ads.googleads.v20.resources.types.campaign_budget import (
4140
CampaignBudget,
4241
)
43-
from google.ads.googleads.v19.resources.types.campaign import Campaign
44-
from google.ads.googleads.v19.common.types.bidding import ManualCpc
42+
from google.ads.googleads.v20.resources.types.campaign import Campaign
43+
from google.ads.googleads.v20.common.types.bidding import ManualCpc
4544

4645

4746
_DATE_FORMAT: str = "%Y%m%d"
@@ -70,10 +69,11 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
7069
# Add budget.
7170
campaign_budget_response: MutateCampaignBudgetsResponse
7271
try:
72+
budget_operations: List[CampaignBudgetOperation] = [campaign_budget_operation]
7373
campaign_budget_response = (
7474
campaign_budget_service.mutate_campaign_budgets(
7575
customer_id=customer_id,
76-
operations=[campaign_budget_operation], # type: ignore
76+
operations=budget_operations,
7777
)
7878
)
7979
except GoogleAdsException as ex:
@@ -98,7 +98,7 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
9898
campaign.status = client.enums.CampaignStatusEnum.PAUSED
9999

100100
# Set the bidding strategy and budget.
101-
campaign.manual_cpc = ManualCpc()
101+
campaign.manual_cpc = client.get_type("ManualCpc")
102102
campaign.campaign_budget = campaign_budget_response.results[0].resource_name
103103

104104
# Set the campaign network options.
@@ -123,8 +123,9 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
123123
# Add the campaign.
124124
campaign_response: MutateCampaignsResponse
125125
try:
126+
campaign_operations: List[CampaignOperation] = [campaign_operation]
126127
campaign_response = campaign_service.mutate_campaigns(
127-
customer_id=customer_id, operations=[campaign_operation] # type: ignore
128+
customer_id=customer_id, operations=campaign_operations
128129
)
129130
print(f"Created campaign {campaign_response.results[0].resource_name}.")
130131
except GoogleAdsException as ex:

examples/basic_operations/get_campaigns.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
import argparse
2222
import sys
23-
from typing import Iterator
23+
from typing import Iterator, List
2424

2525
from google.ads.googleads.client import GoogleAdsClient
2626
from google.ads.googleads.errors import GoogleAdsException
27-
from google.ads.googleads.v19.services.services.google_ads_service import (
27+
from google.ads.googleads.v20.services.services.google_ads_service import (
2828
GoogleAdsServiceClient,
2929
)
30-
from google.ads.googleads.v19.services.types.google_ads_service import (
30+
from google.ads.googleads.v20.services.types.google_ads_service import (
3131
SearchGoogleAdsStreamResponse,
3232
GoogleAdsRow,
3333
)
@@ -50,8 +50,8 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
5050
)
5151

5252
for batch in stream:
53-
row: GoogleAdsRow
54-
for row in batch.results:
53+
rows: List[GoogleAdsRow] = batch.results
54+
for row in rows:
5555
print(
5656
f"Campaign with ID {row.campaign.id} and name "
5757
f'"{row.campaign.name}" was found.'

examples/basic_operations/get_responsive_search_ads.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424

2525
from google.ads.googleads.client import GoogleAdsClient
2626
from google.ads.googleads.errors import GoogleAdsException
27-
from google.ads.googleads.v19.common.types.ad_type_infos import AdTextAsset
28-
from google.ads.googleads.v19.resources.types.ad import Ad
29-
from google.ads.googleads.v19.services.services.google_ads_service import (
27+
from google.ads.googleads.v20.common.types.ad_type_infos import AdTextAsset
28+
from google.ads.googleads.v20.resources.types.ad import Ad
29+
from google.ads.googleads.v20.services.services.google_ads_service import (
3030
GoogleAdsServiceClient,
3131
)
32-
from google.ads.googleads.v19.services.types.google_ads_service import (
33-
GoogleAdsRow,
32+
from google.ads.googleads.v20.services.types.google_ads_service import (
3433
SearchGoogleAdsRequest,
3534
SearchGoogleAdsResponse,
3635
)
@@ -44,12 +43,15 @@ def main(
4443
ga_service: GoogleAdsServiceClient = client.get_service("GoogleAdsService")
4544

4645
query: str = """
47-
SELECT ad_group.id, ad_group_ad.ad.id,
48-
ad_group_ad.ad.responsive_search_ad.headlines,
49-
ad_group_ad.ad.responsive_search_ad.descriptions,
50-
ad_group_ad.status FROM ad_group_ad
51-
WHERE ad_group_ad.ad.type = RESPONSIVE_SEARCH_AD
52-
AND ad_group_ad.status != "REMOVED" """
46+
SELECT
47+
ad_group.id,
48+
ad_group_ad.ad.id,
49+
ad_group_ad.ad.responsive_search_ad.headlines,
50+
ad_group_ad.ad.responsive_search_ad.descriptions,
51+
ad_group_ad.status
52+
FROM ad_group_ad
53+
WHERE ad_group_ad.ad.type = RESPONSIVE_SEARCH_AD
54+
AND ad_group_ad.status != REMOVED"""
5355

5456
# Optional: Specify an ad group ID to restrict search to only a given
5557
# ad group.

examples/basic_operations/pause_ad.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
import argparse
1919
import sys
20-
from typing import MutableSequence
20+
from typing import List
2121

2222
from google.api_core import protobuf_helpers
2323
from google.ads.googleads.client import GoogleAdsClient
2424
from google.ads.googleads.errors import GoogleAdsException
25-
from google.ads.googleads.v19.resources.types.ad_group_ad import AdGroupAd
26-
from google.ads.googleads.v19.services.services.ad_group_ad_service import (
25+
from google.ads.googleads.v20.resources.types.ad_group_ad import AdGroupAd
26+
from google.ads.googleads.v20.services.services.ad_group_ad_service import (
2727
AdGroupAdServiceClient,
2828
)
29-
from google.ads.googleads.v19.services.types.ad_group_ad_service import (
29+
from google.ads.googleads.v20.services.types.ad_group_ad_service import (
3030
AdGroupAdOperation,
3131
MutateAdGroupAdsResponse,
3232
)
@@ -56,10 +56,12 @@ def main(
5656
protobuf_helpers.field_mask(None, ad_group_ad._pb),
5757
)
5858

59+
operations List[AdGroupAdOperation] = [ad_group_ad_operation]
60+
5961
ad_group_ad_response: MutateAdGroupAdsResponse = (
6062
ad_group_ad_service.mutate_ad_group_ads(
6163
customer_id=customer_id,
62-
operations=[ad_group_ad_operation], # type: ignore
64+
operations=operations,
6365
)
6466
)
6567

@@ -99,7 +101,7 @@ def main(
99101
googleads_client = GoogleAdsClient.load_from_storage(version="v20")
100102
=======
101103
googleads_client: GoogleAdsClient = GoogleAdsClient.load_from_storage(
102-
version="v19"
104+
version="v20"
103105
)
104106
>>>>>>> e9e91feee (I've added type hints and annotations to the Python files in your `examples/basic_operations` directory. This should make the code easier to read and also help with static analysis.)
105107
>>>>>>> 6b1491771 (I've added type hints and annotations to the Python files in your `examples/basic_operations` directory. This should make the code easier to read and also help with static analysis.)

examples/basic_operations/remove_campaign.py

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

1818
import argparse
1919
import sys
20-
from typing import MutableSequence
20+
from typing import List
2121

2222
from google.ads.googleads.client import GoogleAdsClient
2323
from google.ads.googleads.errors import GoogleAdsException
24-
from google.ads.googleads.v19.services.services.campaign_service import (
24+
from google.ads.googleads.v20.services.services.campaign_service import (
2525
CampaignServiceClient,
2626
)
27-
from google.ads.googleads.v19.services.types.campaign_service import (
27+
from google.ads.googleads.v20.services.types.campaign_service import (
2828
CampaignOperation,
2929
MutateCampaignsResponse,
3030
)
@@ -41,10 +41,12 @@ def main(client: GoogleAdsClient, customer_id: str, campaign_id: str) -> None:
4141
)
4242
campaign_operation.remove = resource_name
4343

44+
operations: List[CampaignOperation] = [campaign_operation]
45+
4446
campaign_response: MutateCampaignsResponse = (
4547
campaign_service.mutate_campaigns(
4648
customer_id=customer_id,
47-
operations=[campaign_operation], # type: ignore
49+
operations=operations,
4850
)
4951
)
5052

examples/basic_operations/search_for_google_ads_fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626

2727
from google.ads.googleads.client import GoogleAdsClient
2828
from google.ads.googleads.errors import GoogleAdsException
29-
from google.ads.googleads.v19.resources.types.google_ads_field import (
29+
from google.ads.googleads.v20.resources.types.google_ads_field import (
3030
GoogleAdsField,
3131
)
32-
from google.ads.googleads.v19.services.services.google_ads_field_service import (
32+
from google.ads.googleads.v20.services.services.google_ads_field_service import (
3333
GoogleAdsFieldServiceClient,
3434
)
35-
from google.ads.googleads.v19.services.types.google_ads_field_service import (
35+
from google.ads.googleads.v20.services.types.google_ads_field_service import (
3636
SearchGoogleAdsFieldsRequest,
3737
SearchGoogleAdsFieldsResponse,
3838
)

examples/basic_operations/update_ad_group.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020

2121
import argparse
2222
import sys
23-
from typing import MutableSequence
23+
from typing import List
2424

2525
from google.ads.googleads.client import GoogleAdsClient
2626
from google.ads.googleads.errors import GoogleAdsException
27-
from google.ads.googleads.v19.resources.types.ad_group import AdGroup
28-
from google.ads.googleads.v19.services.services.ad_group_service import (
27+
from google.ads.googleads.v20.resources.types.ad_group import AdGroup
28+
from google.ads.googleads.v20.services.services.ad_group_service import (
2929
AdGroupServiceClient,
3030
)
31-
from google.ads.googleads.v19.services.types.ad_group_service import (
31+
from google.ads.googleads.v20.services.types.ad_group_ad_service import AdGroupAdOperation
32+
from google.ads.googleads.v20.services.types.ad_group_service import (
3233
AdGroupOperation,
3334
MutateAdGroupsResponse,
3435
)
@@ -59,11 +60,13 @@ def main(
5960
protobuf_helpers.field_mask(None, ad_group._pb),
6061
)
6162

63+
operations: List[AdGroupAdOperation] = [ad_group_operation]
64+
6265
# Update the ad group.
6366
ad_group_response: MutateAdGroupsResponse = (
6467
ad_group_service.mutate_ad_groups(
6568
customer_id=customer_id,
66-
operations=[ad_group_operation], # type: ignore
69+
operations=operations,
6770
)
6871
)
6972

examples/basic_operations/update_campaign.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020

2121
import argparse
2222
import sys
23-
from typing import MutableSequence
23+
from typing import List
2424

2525
from google.ads.googleads.client import GoogleAdsClient
2626
from google.ads.googleads.errors import GoogleAdsException
27-
from google.ads.googleads.v19.resources.types.campaign import Campaign
28-
from google.ads.googleads.v19.services.services.campaign_service import (
27+
from google.ads.googleads.v20.resources.types.campaign import Campaign
28+
from google.ads.googleads.v20.services.services.campaign_service import (
2929
CampaignServiceClient,
3030
)
31-
from google.ads.googleads.v19.services.types.campaign_service import (
31+
from google.ads.googleads.v20.services.types.campaign_service import (
3232
CampaignOperation,
3333
MutateCampaignsResponse,
3434
)
@@ -56,10 +56,12 @@ def main(client: GoogleAdsClient, customer_id: str, campaign_id: str) -> None:
5656
protobuf_helpers.field_mask(None, campaign._pb),
5757
)
5858

59+
operations: List[CampaignOperation] = [campaign_operation]
60+
5961
campaign_response: MutateCampaignsResponse = (
6062
campaign_service.mutate_campaigns(
6163
customer_id=customer_id,
62-
operations=[campaign_operation], # type: ignore
64+
operations=operations,
6365
)
6466
)
6567

examples/basic_operations/update_responsive_search_ad.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
from google.ads.googleads.client import GoogleAdsClient
2727
from google.ads.googleads.errors import GoogleAdsException
28-
from google.ads.googleads.v19.common.types.ad_type_infos import AdTextAsset
29-
from google.ads.googleads.v19.resources.types.ad import Ad
30-
from google.ads.googleads.v19.services.services.ad_service import (
28+
from google.ads.googleads.v20.common.types.ad_type_infos import AdTextAsset
29+
from google.ads.googleads.v20.resources.types.ad import Ad
30+
from google.ads.googleads.v20.services.services.ad_service import (
3131
AdServiceClient,
3232
)
33-
from google.ads.googleads.v19.services.types.ad_service import (
33+
from google.ads.googleads.v20.services.types.ad_service import (
3434
AdOperation,
3535
MutateAdsResponse,
3636
)
@@ -77,8 +77,9 @@ def main(client: GoogleAdsClient, customer_id: str, ad_id: str) -> None:
7777
)
7878

7979
# Updates the ad.
80+
operations: List[AdOperation] = [ad_operation]
8081
ad_response: MutateAdsResponse = ad_service.mutate_ads(
81-
customer_id=customer_id, operations=[ad_operation] # type: ignore
82+
customer_id=customer_id, operations=operations
8283
)
8384
print(
8485
f'Ad with resource name "{ad_response.results[0].resource_name}" '

0 commit comments

Comments
 (0)