2727
2828from google .ads .googleads .client import GoogleAdsClient
2929from 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+ )
3064
3165
3266def main (
33- client , customer_id , hotel_center_account_id , cpc_bid_ceiling_micro_amount
34- ):
35- budget_resource_name = add_budget (client , customer_id )
36-
37- campaign_resource_name = add_hotel_campaign (
67+ client : GoogleAdsClient ,
68+ customer_id : str ,
69+ hotel_center_account_id : int ,
70+ cpc_bid_ceiling_micro_amount : int ,
71+ ) -> None :
72+ budget_resource_name : str = add_budget (client , customer_id )
73+
74+ campaign_resource_name : str = add_hotel_campaign (
3875 client ,
3976 customer_id ,
4077 budget_resource_name ,
4178 hotel_center_account_id ,
4279 cpc_bid_ceiling_micro_amount ,
4380 )
4481
45- ad_group_resource_name = add_hotel_ad_group (
82+ ad_group_resource_name : str = add_hotel_ad_group (
4683 client , customer_id , campaign_resource_name
4784 )
4885
4986 add_hotel_ad (client , customer_id , ad_group_resource_name )
5087
5188
52- def add_budget (client , customer_id ):
53- campaign_budget_service = client .get_service ("CampaignBudgetService" )
89+ def add_budget (client : GoogleAdsClient , customer_id : str ) -> str :
90+ campaign_budget_service : CampaignBudgetServiceClient = client .get_service (
91+ "CampaignBudgetService"
92+ )
5493
5594 # Create a budget, which can be shared by multiple campaigns.
56- campaign_budget_operation = client .get_type ("CampaignBudgetOperation" )
57- campaign_budget = campaign_budget_operation .create
95+ campaign_budget_operation : CampaignBudgetOperation = client .get_type (
96+ "CampaignBudgetOperation"
97+ )
98+ campaign_budget : CampaignBudget = campaign_budget_operation .create
5899 campaign_budget .name = f"Interplanetary Budget { uuid .uuid4 ()} "
59100 campaign_budget .delivery_method = (
60101 client .enums .BudgetDeliveryMethodEnum .STANDARD
61102 )
62103 campaign_budget .amount_micros = 500000
63104
64105 # Add budget.
65- campaign_budget_response = campaign_budget_service .mutate_campaign_budgets (
66- customer_id = customer_id , operations = [campaign_budget_operation ]
106+ campaign_budget_response : MutateCampaignBudgetsResponse = (
107+ campaign_budget_service .mutate_campaign_budgets (
108+ customer_id = customer_id , operations = [campaign_budget_operation ]
109+ )
67110 )
68111
69- budget_resource_name = campaign_budget_response .results [0 ].resource_name
112+ budget_resource_name : str = campaign_budget_response .results [
113+ 0
114+ ].resource_name
70115
71116 print (f"Created budget with resource name '{ budget_resource_name } '." )
72117
73118 return budget_resource_name
74119
75120
76121# [START add_hotel_ad_3]
77- def add_hotel_ad (client , customer_id , ad_group_resource_name ):
78- ad_group_ad_service = client .get_service ("AdGroupAdService" )
122+ def add_hotel_ad (
123+ client : GoogleAdsClient , customer_id : str , ad_group_resource_name : str
124+ ) -> str :
125+ ad_group_ad_service : AdGroupAdServiceClient = client .get_service (
126+ "AdGroupAdService"
127+ )
79128
80129 # Creates a new ad group ad and sets the hotel ad to it.
81- ad_group_ad_operation = client .get_type ("AdGroupAdOperation" )
82- ad_group_ad = 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
83132 ad_group_ad .ad_group = ad_group_resource_name
84133 # Set the ad group ad to enabled. Setting this to paused will cause an error
85134 # for hotel campaigns. For hotels pausing should happen at either the ad group or
@@ -88,11 +137,13 @@ def add_hotel_ad(client, customer_id, ad_group_resource_name):
88137 client .copy_from (ad_group_ad .ad .hotel_ad , client .get_type ("HotelAdInfo" ))
89138
90139 # Add the ad group ad.
91- ad_group_ad_response = ad_group_ad_service .mutate_ad_group_ads (
140+ ad_group_ad_response : MutateAdGroupAdsResponse = ad_group_ad_service .mutate_ad_group_ads (
92141 customer_id = customer_id , operations = [ad_group_ad_operation ]
93142 )
94143
95- ad_group_ad_resource_name = ad_group_ad_response .results [0 ].resource_name
144+ ad_group_ad_resource_name : str = ad_group_ad_response .results [
145+ 0
146+ ].resource_name
96147
97148 print (f"Created hotel ad with resource name '{ ad_group_ad_resource_name } '." )
98149
@@ -101,12 +152,14 @@ def add_hotel_ad(client, customer_id, ad_group_resource_name):
101152
102153
103154# [START add_hotel_ad_2]
104- def add_hotel_ad_group (client , customer_id , campaign_resource_name ):
105- ad_group_service = client .get_service ("AdGroupService" )
155+ def add_hotel_ad_group (
156+ client : GoogleAdsClient , customer_id : str , campaign_resource_name : str
157+ ) -> str :
158+ ad_group_service : AdGroupServiceClient = client .get_service ("AdGroupService" )
106159
107160 # Create ad group.
108- ad_group_operation = client .get_type ("AdGroupOperation" )
109- ad_group = ad_group_operation .create
161+ ad_group_operation : AdGroupOperation = client .get_type ("AdGroupOperation" )
162+ ad_group : AdGroup = ad_group_operation .create
110163 ad_group .name = f"Earth to Mars cruise { uuid .uuid4 ()} "
111164 ad_group .status = client .enums .AdGroupStatusEnum .ENABLED
112165 ad_group .campaign = campaign_resource_name
@@ -115,11 +168,11 @@ def add_hotel_ad_group(client, customer_id, campaign_resource_name):
115168 ad_group .cpc_bid_micros = 10000000
116169
117170 # Add the ad group.
118- ad_group_response = ad_group_service .mutate_ad_groups (
171+ ad_group_response : MutateAdGroupsResponse = ad_group_service .mutate_ad_groups (
119172 customer_id = customer_id , operations = [ad_group_operation ]
120173 )
121174
122- ad_group_resource_name = ad_group_response .results [0 ].resource_name
175+ ad_group_resource_name : str = ad_group_response .results [0 ].resource_name
123176
124177 print (
125178 "Added a hotel ad group with resource name '{ad_group_resource_name}'."
@@ -131,18 +184,18 @@ def add_hotel_ad_group(client, customer_id, campaign_resource_name):
131184
132185# [START add_hotel_ad]
133186def add_hotel_campaign (
134- client ,
135- customer_id ,
136- budget_resource_name ,
137- hotel_center_account_id ,
138- cpc_bid_ceiling_micro_amount ,
139- ):
140- campaign_service = client .get_service ("CampaignService" )
187+ client : GoogleAdsClient ,
188+ customer_id : str ,
189+ budget_resource_name : str ,
190+ hotel_center_account_id : int ,
191+ cpc_bid_ceiling_micro_amount : int ,
192+ ) -> str :
193+ campaign_service : CampaignServiceClient = client .get_service ("CampaignService" )
141194
142195 # [START add_hotel_ad_1]
143196 # Create campaign.
144- campaign_operation = client .get_type ("CampaignOperation" )
145- campaign = campaign_operation .create
197+ campaign_operation : CampaignOperation = client .get_type ("CampaignOperation" )
198+ campaign : Campaign = campaign_operation .create
146199 campaign .name = f"Interplanetary Cruise Campaign { uuid .uuid4 ()} "
147200
148201 # Configures settings related to hotel campaigns including advertising
@@ -170,11 +223,11 @@ def add_hotel_campaign(
170223 # [END add_hotel_ad_1]
171224
172225 # Add the campaign.
173- campaign_response = campaign_service .mutate_campaigns (
226+ campaign_response : MutateCampaignsResponse = campaign_service .mutate_campaigns (
174227 customer_id = customer_id , operations = [campaign_operation ]
175228 )
176229
177- campaign_resource_name = campaign_response .results [0 ].resource_name
230+ campaign_resource_name : str = campaign_response .results [0 ].resource_name
178231
179232 print (
180233 "Added a hotel campaign with resource name '{campaign_resource_name}'."
@@ -185,7 +238,7 @@ def add_hotel_campaign(
185238
186239
187240if __name__ == "__main__" :
188- parser = argparse .ArgumentParser (
241+ parser : argparse . ArgumentParser = argparse .ArgumentParser (
189242 description = (
190243 "Adds an expanded text ad to the specified ad group ID, "
191244 "for the given customer ID."
@@ -213,11 +266,13 @@ def add_hotel_campaign(
213266 required = True ,
214267 help = "The hotel center account ID." ,
215268 )
216- args = parser .parse_args ()
269+ args : argparse . Namespace = parser .parse_args ()
217270
218271 # GoogleAdsClient will read the google-ads.yaml configuration file in the
219272 # home directory if none is specified.
220- googleads_client = GoogleAdsClient .load_from_storage (version = "v20" )
273+ googleads_client : GoogleAdsClient = GoogleAdsClient .load_from_storage (
274+ version = "v20"
275+ )
221276
222277 try :
223278 main (
0 commit comments