Skip to content

Commit 0cc1298

Browse files
committed
Update travel examples with correct annotations
Change-Id: Ibc9a917f3d34d3c53ddd030d034c63047593ce02
1 parent b097bac commit 0cc1298

File tree

5 files changed

+365
-175
lines changed

5 files changed

+365
-175
lines changed

examples/travel/add_hotel_ad.py

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,43 @@
2424
import argparse
2525
import sys
2626
import uuid
27-
from typing import Any
2827

2928
from google.ads.googleads.client import GoogleAdsClient
3029
from google.ads.googleads.errors import GoogleAdsException
30+
from google.ads.googleads.v20.resources.types.ad_group import AdGroup
31+
from google.ads.googleads.v20.resources.types.ad_group_ad import AdGroupAd
32+
from google.ads.googleads.v20.resources.types.campaign import Campaign
33+
from google.ads.googleads.v20.resources.types.campaign_budget import (
34+
CampaignBudget,
35+
)
36+
from google.ads.googleads.v20.services.services.ad_group_ad_service import (
37+
AdGroupAdServiceClient,
38+
)
39+
from google.ads.googleads.v20.services.services.ad_group_service import (
40+
AdGroupServiceClient,
41+
)
42+
from google.ads.googleads.v20.services.services.campaign_budget_service import (
43+
CampaignBudgetServiceClient,
44+
)
45+
from google.ads.googleads.v20.services.services.campaign_service import (
46+
CampaignServiceClient,
47+
)
48+
from google.ads.googleads.v20.services.types.ad_group_ad_service import (
49+
AdGroupAdOperation,
50+
MutateAdGroupAdsResponse,
51+
)
52+
from google.ads.googleads.v20.services.types.ad_group_service import (
53+
AdGroupOperation,
54+
MutateAdGroupsResponse,
55+
)
56+
from google.ads.googleads.v20.services.types.campaign_budget_service import (
57+
CampaignBudgetOperation,
58+
MutateCampaignBudgetsResponse,
59+
)
60+
from google.ads.googleads.v20.services.types.campaign_service import (
61+
CampaignOperation,
62+
MutateCampaignsResponse,
63+
)
3164

3265

3366
def main(
@@ -54,19 +87,23 @@ def main(
5487

5588

5689
def add_budget(client: GoogleAdsClient, customer_id: str) -> str:
57-
campaign_budget_service: Any = client.get_service("CampaignBudgetService")
90+
campaign_budget_service: CampaignBudgetServiceClient = client.get_service(
91+
"CampaignBudgetService"
92+
)
5893

5994
# Create a budget, which can be shared by multiple campaigns.
60-
campaign_budget_operation: Any = client.get_type("CampaignBudgetOperation")
61-
campaign_budget: Any = campaign_budget_operation.create
95+
campaign_budget_operation: CampaignBudgetOperation = client.get_type(
96+
"CampaignBudgetOperation"
97+
)
98+
campaign_budget: CampaignBudget = campaign_budget_operation.create
6299
campaign_budget.name = f"Interplanetary Budget {uuid.uuid4()}"
63100
campaign_budget.delivery_method = (
64101
client.enums.BudgetDeliveryMethodEnum.STANDARD
65102
)
66103
campaign_budget.amount_micros = 500000
67104

68105
# Add budget.
69-
campaign_budget_response: Any = (
106+
campaign_budget_response: MutateCampaignBudgetsResponse = (
70107
campaign_budget_service.mutate_campaign_budgets(
71108
customer_id=customer_id, operations=[campaign_budget_operation]
72109
)
@@ -85,11 +122,13 @@ def add_budget(client: GoogleAdsClient, customer_id: str) -> str:
85122
def add_hotel_ad(
86123
client: GoogleAdsClient, customer_id: str, ad_group_resource_name: str
87124
) -> str:
88-
ad_group_ad_service: Any = client.get_service("AdGroupAdService")
125+
ad_group_ad_service: AdGroupAdServiceClient = client.get_service(
126+
"AdGroupAdService"
127+
)
89128

90129
# Creates a new ad group ad and sets the hotel ad to it.
91-
ad_group_ad_operation: Any = client.get_type("AdGroupAdOperation")
92-
ad_group_ad: Any = ad_group_ad_operation.create
130+
ad_group_ad_operation: AdGroupAdOperation = client.get_type("AdGroupAdOperation")
131+
ad_group_ad: AdGroupAd = ad_group_ad_operation.create
93132
ad_group_ad.ad_group = ad_group_resource_name
94133
# Set the ad group ad to enabled. Setting this to paused will cause an error
95134
# for hotel campaigns. For hotels pausing should happen at either the ad group or
@@ -98,7 +137,7 @@ def add_hotel_ad(
98137
client.copy_from(ad_group_ad.ad.hotel_ad, client.get_type("HotelAdInfo"))
99138

100139
# Add the ad group ad.
101-
ad_group_ad_response: Any = ad_group_ad_service.mutate_ad_group_ads(
140+
ad_group_ad_response: MutateAdGroupAdsResponse = ad_group_ad_service.mutate_ad_group_ads(
102141
customer_id=customer_id, operations=[ad_group_ad_operation]
103142
)
104143

@@ -116,11 +155,11 @@ def add_hotel_ad(
116155
def add_hotel_ad_group(
117156
client: GoogleAdsClient, customer_id: str, campaign_resource_name: str
118157
) -> str:
119-
ad_group_service: Any = client.get_service("AdGroupService")
158+
ad_group_service: AdGroupServiceClient = client.get_service("AdGroupService")
120159

121160
# Create ad group.
122-
ad_group_operation: Any = client.get_type("AdGroupOperation")
123-
ad_group: Any = ad_group_operation.create
161+
ad_group_operation: AdGroupOperation = client.get_type("AdGroupOperation")
162+
ad_group: AdGroup = ad_group_operation.create
124163
ad_group.name = f"Earth to Mars cruise {uuid.uuid4()}"
125164
ad_group.status = client.enums.AdGroupStatusEnum.ENABLED
126165
ad_group.campaign = campaign_resource_name
@@ -129,7 +168,7 @@ def add_hotel_ad_group(
129168
ad_group.cpc_bid_micros = 10000000
130169

131170
# Add the ad group.
132-
ad_group_response: Any = ad_group_service.mutate_ad_groups(
171+
ad_group_response: MutateAdGroupsResponse = ad_group_service.mutate_ad_groups(
133172
customer_id=customer_id, operations=[ad_group_operation]
134173
)
135174

@@ -151,12 +190,12 @@ def add_hotel_campaign(
151190
hotel_center_account_id: int,
152191
cpc_bid_ceiling_micro_amount: int,
153192
) -> str:
154-
campaign_service: Any = client.get_service("CampaignService")
193+
campaign_service: CampaignServiceClient = client.get_service("CampaignService")
155194

156195
# [START add_hotel_ad_1]
157196
# Create campaign.
158-
campaign_operation: Any = client.get_type("CampaignOperation")
159-
campaign: Any = campaign_operation.create
197+
campaign_operation: CampaignOperation = client.get_type("CampaignOperation")
198+
campaign: Campaign = campaign_operation.create
160199
campaign.name = f"Interplanetary Cruise Campaign {uuid.uuid4()}"
161200

162201
# Configures settings related to hotel campaigns including advertising
@@ -184,7 +223,7 @@ def add_hotel_campaign(
184223
# [END add_hotel_ad_1]
185224

186225
# Add the campaign.
187-
campaign_response: Any = campaign_service.mutate_campaigns(
226+
campaign_response: MutateCampaignsResponse = campaign_service.mutate_campaigns(
188227
customer_id=customer_id, operations=[campaign_operation]
189228
)
190229

examples/travel/add_hotel_ad_group_bid_modifiers.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,40 @@
2020

2121
import argparse
2222
import sys
23-
from typing import Any
2423

2524
from google.ads.googleads.client import GoogleAdsClient
2625
from google.ads.googleads.errors import GoogleAdsException
26+
from google.ads.googleads.v20.common.types.criteria import HotelLengthOfStayInfo
27+
from google.ads.googleads.v20.resources.types.ad_group_bid_modifier import (
28+
AdGroupBidModifier,
29+
)
30+
from google.ads.googleads.v20.services.services.ad_group_bid_modifier_service import (
31+
AdGroupBidModifierServiceClient,
32+
)
33+
from google.ads.googleads.v20.services.services.ad_group_service import (
34+
AdGroupServiceClient,
35+
)
36+
from google.ads.googleads.v20.services.types.ad_group_bid_modifier_service import (
37+
AdGroupBidModifierOperation,
38+
MutateAdGroupBidModifierResult,
39+
MutateAdGroupBidModifiersResponse,
40+
)
2741

2842

2943
# [START add_hotel_ad_group_bid_modifiers]
3044
def main(client: GoogleAdsClient, customer_id: str, ad_group_id: str) -> None:
31-
ad_group_service: Any = client.get_service("AdGroupService")
32-
ag_bm_service: Any = client.get_service("AdGroupBidModifierService")
45+
ad_group_service: AdGroupServiceClient = client.get_service("AdGroupService")
46+
ag_bm_service: AdGroupBidModifierServiceClient = client.get_service(
47+
"AdGroupBidModifierService"
48+
)
3349

3450
# Create ad group bid modifier based on hotel check-in day.
35-
check_in_ag_bm_operation: Any = client.get_type(
51+
check_in_ag_bm_operation: AdGroupBidModifierOperation = client.get_type(
3652
"AdGroupBidModifierOperation"
3753
)
38-
check_in_ag_bid_modifier: Any = check_in_ag_bm_operation.create
54+
check_in_ag_bid_modifier: AdGroupBidModifier = (
55+
check_in_ag_bm_operation.create
56+
)
3957
check_in_ag_bid_modifier.hotel_check_in_day.day_of_week = (
4058
client.enums.DayOfWeekEnum.MONDAY
4159
)
@@ -46,13 +64,15 @@ def main(client: GoogleAdsClient, customer_id: str, ad_group_id: str) -> None:
4664
check_in_ag_bid_modifier.bid_modifier = 1.5
4765

4866
# Create ad group bid modifier based on hotel length of stay info.
49-
los_ag_bm_operation: Any = client.get_type("AdGroupBidModifierOperation")
50-
los_ag_bid_modifier: Any = los_ag_bm_operation.create
67+
los_ag_bm_operation: AdGroupBidModifierOperation = client.get_type(
68+
"AdGroupBidModifierOperation"
69+
)
70+
los_ag_bid_modifier: AdGroupBidModifier = los_ag_bm_operation.create
5171
los_ag_bid_modifier.ad_group = ad_group_service.ad_group_path(
5272
customer_id, ad_group_id
5373
)
5474
# Creates the hotel length of stay info.
55-
hotel_length_of_stay_info: Any = (
75+
hotel_length_of_stay_info: HotelLengthOfStayInfo = (
5676
los_ag_bid_modifier.hotel_length_of_stay
5777
)
5878
hotel_length_of_stay_info.min_nights = 3
@@ -61,14 +81,17 @@ def main(client: GoogleAdsClient, customer_id: str, ad_group_id: str) -> None:
6181
los_ag_bid_modifier.bid_modifier = 1.7
6282

6383
# Add the bid modifiers
64-
ag_bm_response: Any = ag_bm_service.mutate_ad_group_bid_modifiers(
65-
customer_id=customer_id,
66-
operations=[check_in_ag_bm_operation, los_ag_bm_operation],
84+
ag_bm_response: MutateAdGroupBidModifiersResponse = (
85+
ag_bm_service.mutate_ad_group_bid_modifiers(
86+
customer_id=customer_id,
87+
operations=[check_in_ag_bm_operation, los_ag_bm_operation],
88+
)
6789
)
6890

6991
# Print out resource names of the added ad group bid modifiers.
7092
print(f"Added {len(ag_bm_response.results)} hotel ad group bid modifiers:")
7193

94+
result: MutateAdGroupBidModifierResult
7295
for result in ag_bm_response.results:
7396
print(result.resource_name)
7497
# [END add_hotel_ad_group_bid_modifiers]

0 commit comments

Comments
 (0)