Best Python code snippet using robotframework
keywords.py
Source:keywords.py
...5# This module is part of python-sqlparse and is released under6# the BSD License: http://www.opensource.org/licenses/bsd-license.php7import re8from sqlparse import tokens9def is_keyword(value):10 val = value.upper()11 return (KEYWORDS_COMMON.get(val) or12 KEYWORDS_ORACLE.get(val) or13 KEYWORDS.get(val, tokens.Name)), value14SQL_REGEX = {15 'root': [16 (r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),17 (r'/\*\+[\s\S]*?\*/', tokens.Comment.Multiline.Hint),18 (r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),19 (r'/\*[\s\S]*?\*/', tokens.Comment.Multiline),20 (r'(\r\n|\r|\n)', tokens.Newline),21 (r'\s+', tokens.Whitespace),22 (r':=', tokens.Assignment),23 (r'::', tokens.Punctuation),...
sldisplayables.py
Source:sldisplayables.py
1# Copyright 2004-2014 Tom Rothamel <pytom@bishoujo.us>2#3# Permission is hereby granted, free of charge, to any person4# obtaining a copy of this software and associated documentation files5# (the "Software"), to deal in the Software without restriction,6# including without limitation the rights to use, copy, modify, merge,7# publish, distribute, sublicense, and/or sell copies of the Software,8# and to permit persons to whom the Software is furnished to do so,9# subject to the following conditions:10#11# The above copyright notice and this permission notice shall be12# included in all copies or substantial portions of the Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE18# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION19# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION20# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21##############################################################################22# Definitions of screen language statements.23import renpy.display24import renpy.text.text25class ShowIf(renpy.display.layout.Container):26 """27 This is a displayable that wraps displayables that are28 underneath a showif statement.29 """30 def __init__(self, condition, replaces=None):31 super(ShowIf, self).__init__()32 self.condition = condition33 if replaces is None:34 if condition:35 self.pending_event = "appear"36 else:37 self.pending_event = None38 self.show_child = condition39 else:40 if self.condition and not replaces.condition:41 self.pending_event = "show"42 elif not self.condition and replaces.condition:43 self.pending_event = "hide"44 else:45 self.pending_event = replaces.pending_event46 self.show_child = replaces.show_child47 def per_interact(self):48 if self.pending_event:49 self.child.set_transform_event(self.pending_event)50 self.pending_event = None51 def render(self, width, height, st, at):52 if isinstance(self.child, renpy.display.motion.Transform):53 if self.condition or self.show_child:54 cr = renpy.display.render.render(self.child, width, height, st, at)55 self.show_child = self.condition or not self.child.hide_response56 else:57 if self.condition:58 cr = renpy.display.render.render(self.child, width, height, st, at)59 self.show_child = True60 else:61 self.show_child = False62 if self.show_child:63 cw, ch = cr.get_size()64 rv = renpy.display.render.Render(cw, ch)65 rv.blit(cr, (0, 0))66 else:67 rv = renpy.display.render.Render(0, 0)68 self.offsets = [ (0, 0) ]69 return rv70 def event(self, ev, x, y, st):71 if self.condition:72 return self.child.event(ev, x, y, st)73 else:74 return None75 def get_placement(self):76 return self.child.get_placement()77from renpy.sl2.slparser import Positional, Keyword, Style, PrefixStyle, add78from renpy.sl2.slparser import DisplayableParser, many79position_property_names = [80 "anchor",81 "xanchor",82 "yanchor",83 "pos",84 "xpos",85 "ypos",86 "align",87 "xalign",88 "yalign",89 "xoffset",90 "yoffset",91 "maximum",92 "xmaximum",93 "ymaximum",94 "area",95 "clipping",96 "xfill",97 "yfill",98 # no center, since it can conflict with the center transform.99 "xcenter",100 "ycenter",101 "xsize",102 "ysize",103 "xysize",104 "alt",105 "debug",106 ]107position_properties = [ Style(i) for i in position_property_names ]108text_position_properties = [ PrefixStyle("text_", i) for i in position_property_names ]109side_position_properties = [ PrefixStyle("side_", i) for i in position_property_names ]110text_property_names = [111 "antialias",112 "vertical",113 "black_color",114 "bold",115 "color",116 "drop_shadow",117 "drop_shadow_color",118 "first_indent",119 "font",120 "size",121 "hyperlink_functions",122 "italic",123 "justify",124 "kerning",125 "language",126 "layout",127 "line_leading",128 "line_spacing",129 "minwidth",130 "min_width",131 "newline_indent",132 "outlines",133 "rest_indent",134 "ruby_style",135 "slow_cps",136 "slow_cps_multiplier",137 "slow_abortable",138 "strikethrough",139 "text_align",140 "text_y_fudge",141 "underline",142 "minimum",143 "xminimum",144 "yminimum",145 ]146text_properties = [ Style(i) for i in text_property_names ]147text_text_properties = [ PrefixStyle("text_", i) for i in text_property_names ]148window_properties = [ Style(i) for i in [149 "background",150 "foreground",151 "left_margin",152 "right_margin",153 "bottom_margin",154 "top_margin",155 "xmargin",156 "ymargin",157 "left_padding",158 "right_padding",159 "top_padding",160 "bottom_padding",161 "xpadding",162 "ypadding",163 "size_group",164 "minimum",165 "xminimum",166 "yminimum",167 ] ]168button_properties = [ Style(i) for i in [169 "sound",170 "mouse",171 "focus_mask",172 "child",173 "keyboard_focus",174 ] ]175bar_properties = [ Style(i) for i in [176 "bar_vertical",177 "bar_invert",178 "bar_resizing",179 "left_gutter",180 "right_gutter",181 "top_gutter",182 "bottom_gutter",183 "left_bar",184 "right_bar",185 "top_bar",186 "bottom_bar",187 "thumb",188 "thumb_shadow",189 "thumb_offset",190 "mouse",191 "unscrollable",192 "keyboard_focus",193 ] ]194box_properties = [ Style(i) for i in [195 "box_layout",196 "box_wrap",197 "box_reverse",198 "order_reverse",199 "spacing",200 "first_spacing",201 "fit_first",202 "minimum",203 "xminimum",204 "yminimum",205 ] ]206ui_properties = [207 Keyword("at"),208 Keyword("id"),209 Keyword("style"),210 Keyword("style_group"),211 Keyword("focus"),212 Keyword("default"),213 ]214DisplayableParser("null", renpy.display.layout.Null, "default", 0)215Keyword("width")216Keyword("height")217add(ui_properties)218add(position_properties)219DisplayableParser("text", renpy.text.text.Text, "text", 0, scope=True, replaces=True)220Positional("text")221Keyword("slow")222Keyword("slow_done")223Keyword("substitute")224Keyword("scope")225add(ui_properties)226add(position_properties)227add(text_properties)228DisplayableParser("hbox", renpy.display.layout.MultiBox, "hbox", many, default_keywords={ 'layout' : 'horizontal' })229add(ui_properties)230add(position_properties)231add(box_properties)232DisplayableParser("vbox", renpy.display.layout.MultiBox, "vbox", many, default_keywords={ 'layout' : 'vertical' })233add(ui_properties)234add(position_properties)235add(box_properties)236DisplayableParser("fixed", renpy.display.layout.MultiBox, "fixed", many, default_keywords={ 'layout' : 'fixed' })237add(ui_properties)238add(position_properties)239add(box_properties)240DisplayableParser("grid", renpy.display.layout.Grid, "grid", many)241Positional("cols")242Positional("rows")243Keyword("transpose")244Style("spacing")245add(ui_properties)246add(position_properties)247DisplayableParser("side", renpy.display.layout.Side, "side", many)248Positional("positions")249Style("spacing")250add(ui_properties)251add(position_properties)252# Omit sizer, as we can always just put an xmaximum and ymaximum on an item.253for name in [ "window", "frame" ]:254 DisplayableParser(name, renpy.display.layout.Window, name, 1)255 add(ui_properties)256 add(position_properties)257 add(window_properties)258DisplayableParser("key", renpy.ui._key, None, 0)259Positional("key")260Keyword("action")261DisplayableParser("timer", renpy.display.behavior.Timer, "default", 0, replaces=True)262Positional("delay")263Keyword("action")264Keyword("repeat")265# Omit behaviors.266# Omit menu as being too high-level.267DisplayableParser("input", renpy.display.behavior.Input, "input", 0, replaces=True)268Keyword("default")269Keyword("length")270Keyword("allow")271Keyword("exclude")272Keyword("prefix")273Keyword("suffix")274Keyword("changed")275Keyword("pixel_width")276add(ui_properties)277add(position_properties)278add(text_properties)279DisplayableParser("image", renpy.display.im.image, "default", 0)280Positional("im")281# Omit imagemap_compat for being too high level (and obsolete).282DisplayableParser("button", renpy.display.behavior.Button, "button", 1)283Keyword("action")284Keyword("clicked")285Keyword("hovered")286Keyword("unhovered")287Keyword("alternate")288add(ui_properties)289add(position_properties)290add(window_properties)291add(button_properties)292DisplayableParser("imagebutton", renpy.ui._imagebutton, "image_button", 0)293Keyword("auto")294Keyword("idle")295Keyword("hover")296Keyword("insensitive")297Keyword("selected_idle")298Keyword("selected_hover")299Keyword("selected_insensitive")300Keyword("action")301Keyword("clicked")302Keyword("hovered")303Keyword("unhovered")304Keyword("alternate")305Keyword("image_style")306add(ui_properties)307add(position_properties)308add(window_properties)309add(button_properties)310DisplayableParser("textbutton", renpy.ui._textbutton, 0, scope=True)311Positional("label")312Keyword("action")313Keyword("clicked")314Keyword("hovered")315Keyword("unhovered")316Keyword("alternate")317Keyword("text_style")318Keyword("substitute")319Keyword("scope")320add(ui_properties)321add(position_properties)322add(window_properties)323add(button_properties)324add(text_position_properties)325add(text_text_properties)326DisplayableParser("label", renpy.ui._label, "label", 0, scope=True)327Positional("label")328Keyword("text_style")329add(ui_properties)330add(position_properties)331add(window_properties)332add(text_position_properties)333add(text_text_properties)334def sl2bar(context=None, **properties):335 range = 1 #@ReservedAssignment336 value = 0337 width = None338 height = None339 if "width" in properties:340 width = properties.pop("width")341 if "height" in properties:342 height = properties.pop("height")343 if "range" in properties:344 range = properties.pop("range") #@ReservedAssignment345 if "value" in properties:346 value = properties.pop("value")347 if "style" not in properties:348 if isinstance(value, renpy.ui.BarValue):349 style = context.style_prefix + value.get_style()[0]350 properties["style"] = style351 return renpy.display.behavior.Bar(range, value, width, height, vertical=False, **properties)352DisplayableParser("bar", sl2bar, None, 0, replaces=True, pass_context=True)353Keyword("adjustment")354Keyword("range")355Keyword("value")356Keyword("changed")357Keyword("hovered")358Keyword("unhovered")359add(ui_properties)360add(position_properties)361add(bar_properties)362def sl2vbar(context=None, **properties):363 range = 1 #@ReservedAssignment364 value = 0365 width = None366 height = None367 if "width" in properties:368 width = properties.pop("width")369 if "height" in properties:370 height = properties.pop("height")371 if "range" in properties:372 range = properties.pop("range") #@ReservedAssignment373 if "value" in properties:374 value = properties.pop("value")375 if "style" not in properties:376 if isinstance(value, renpy.ui.BarValue):377 style = context.style_prefix + value.get_style()[1]378 properties["style"] = style379 return renpy.display.behavior.Bar(range, value, width, height, vertical=True, **properties)380DisplayableParser("vbar", sl2vbar, None, 0, replaces=True, pass_context=True)381Keyword("adjustment")382Keyword("range")383Keyword("value")384Keyword("changed")385Keyword("hovered")386Keyword("unhovered")387add(ui_properties)388add(position_properties)389add(bar_properties)390# Omit autobar. (behavior)391def sl2viewport(**kwargs):392 """393 This converts the output of renpy.ui.viewport into something that394 sl.displayable can use.395 """396 d = renpy.ui.detached()397 vp = renpy.ui.viewport(**kwargs)398 renpy.ui.stack.pop()399 rv = d.child400 rv._main = vp401 rv._composite_parts = list(rv.children)402 return rv403DisplayableParser("viewport", sl2viewport, "viewport", 1, replaces=True)404Keyword("child_size")405Keyword("mousewheel")406Keyword("draggable")407Keyword("edgescroll")408Keyword("xadjustment")409Keyword("yadjustment")410Keyword("xinitial")411Keyword("yinitial")412Keyword("scrollbars")413PrefixStyle("side_", "spacing")414add(ui_properties)415add(position_properties)416add(side_position_properties)417DisplayableParser("imagemap", renpy.ui._imagemap, "imagemap", many, imagemap=True)418Keyword("ground")419Keyword("hover")420Keyword("insensitive")421Keyword("idle")422Keyword("selected_hover")423Keyword("selected_idle")424Keyword("selected_insensitive")425Keyword("auto")426Keyword("alpha")427Keyword("cache")428add(ui_properties)429add(position_properties)430DisplayableParser("hotspot", renpy.ui._hotspot, "hotspot", 1)431Positional("spot")432Keyword("action")433Keyword("clicked")434Keyword("hovered")435Keyword("unhovered")436add(ui_properties)437add(position_properties)438add(window_properties)439add(button_properties)440DisplayableParser("hotbar", renpy.ui._hotbar, "hotbar", 0, replaces=True)441Positional("spot")442Keyword("adjustment")443Keyword("range")444Keyword("value")445add(ui_properties)446add(position_properties)447add(bar_properties)448DisplayableParser("transform", renpy.display.motion.Transform, "transform", 1)449Keyword("at")450Keyword("id")451for i in renpy.atl.PROPERTIES:452 Style(i)453def sl2add(d, replaces=None, **kwargs):454 d = renpy.easy.displayable(d)455 d = d.parameterize('displayable', [ ])456 rv = d457 Transform = renpy.display.motion.Transform458 if kwargs:459 rv = Transform(child=d, **kwargs)460 if isinstance(rv, Transform):461 rv.take_state(replaces)462 rv.take_execution_state(replaces)463 return rv464DisplayableParser("add", sl2add, None, 0, replaces=True)465Positional("im")466Keyword("at")467Keyword("id")468for i in renpy.atl.PROPERTIES:469 Style(i)470DisplayableParser("drag", renpy.display.dragdrop.Drag, None, 1, replaces=True)471Keyword("drag_name")472Keyword("draggable")473Keyword("droppable")474Keyword("drag_raise")475Keyword("dragged")476Keyword("dropped")477Keyword("drag_handle")478Keyword("drag_joined")479Keyword("clicked")480Keyword("hovered")481Keyword("unhovered")482Style("child")483add(ui_properties)484add(position_properties)485DisplayableParser("draggroup", renpy.display.dragdrop.DragGroup, None, many, replaces=True)486add(ui_properties)487add(position_properties)488DisplayableParser("mousearea", renpy.display.behavior.MouseArea, 0, replaces=True)489Keyword("hovered")490Keyword("unhovered")491Style("focus_mask")492add(ui_properties)493add(position_properties)494DisplayableParser("on", renpy.display.behavior.OnEvent, None, 0)495Positional("event")...
test_facts_minion.py
Source:test_facts_minion.py
...249 assert self.fact_keyword.resolve(self.keyword,self.overlord_value,fact_value) == True250 overlord_tuple = ("os__lt","33")251 self.__prepare_overlord_word(overlord_tuple)252 assert self.fact_keyword.resolve(self.keyword,self.overlord_value,fact_value) == False253 def test_keyword(self):254 """255 Test if it contains256 """257 fact_value = "fedora10"258 overlord_tuple = ("os","fedora10")259 self.__prepare_overlord_word(overlord_tuple)260 assert self.fact_keyword.resolve(self.keyword,self.overlord_value,fact_value) == True261 overlord_tuple = ("os","fedora")262 self.__prepare_overlord_word(overlord_tuple)263 assert self.fact_keyword.resolve(self.keyword,self.overlord_value,fact_value) == False264 fact_value = 100265 overlord_tuple = ("os",100)266 self.__prepare_overlord_word(overlord_tuple)267 assert self.fact_keyword.resolve(self.keyword,self.overlord_value,fact_value) == True...
add_keyword_plan.py
Source:add_keyword_plan.py
1#!/usr/bin/env python2# Copyright 2019 Google LLC3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# https://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""This example creates a keyword plan.16Keyword plans can be reused for retrieving forecast metrics and historic17metrics.18"""19import argparse20import sys21import uuid22from google.ads.googleads.client import GoogleAdsClient23from google.ads.googleads.errors import GoogleAdsException24# [START add_keyword_plan]25def GA_add_kw_plan(client, customer_id):26 """Adds a keyword plan, campaign, ad group, etc. to the customer account.27 Also handles errors from the API and prints them.28 Args:29 client: An initialized instance of GoogleAdsClient30 customer_id: A str of the customer_id to use in requests.31 """32 _add_keyword_plan(client, customer_id)33def _add_keyword_plan(client, customer_id):34 """Adds a keyword plan, campaign, ad group, etc. to the customer account.35 Args:36 client: An initialized instance of GoogleAdsClient37 customer_id: A str of the customer_id to use in requests.38 Raises:39 GoogleAdsException: If an error is returned from the API.40 """41 keyword_plan = _create_keyword_plan(client, customer_id)42 43 keyword_plan_campaign = _create_keyword_plan_campaign(44 client, customer_id, keyword_plan45 )46 47 keyword_plan_ad_group = _create_keyword_plan_ad_group(48 client, customer_id, keyword_plan_campaign49 )50 51 _create_keyword_plan_ad_group_keywords(52 client, customer_id, keyword_plan_ad_group53 )54 55 _create_keyword_plan_negative_campaign_keywords(56 client, customer_id, keyword_plan_campaign57 )58def _create_keyword_plan(client, customer_id):59 """Adds a keyword plan to the given customer account.60 Args:61 client: An initialized instance of GoogleAdsClient62 customer_id: A str of the customer_id to use in requests.63 Returns:64 A str of the resource_name for the newly created keyword plan.65 Raises:66 GoogleAdsException: If an error is returned from the API.67 """68 keyword_plan_service = client.get_service("KeywordPlanService")69 70 operation = client.get_type("KeywordPlanOperation")71 72 keyword_plan = operation.create73#need a variable called keyword_plan_name74 keyword_plan.name = f"Keyword plan for traffic estimate {uuid.uuid4()}"75 forecast_interval = client.get_type(76 "KeywordPlanForecastIntervalEnum"77 ).KeywordPlanForecastInterval.NEXT_QUARTER78 79 keyword_plan.forecast_period.date_interval = forecast_interval80 response = keyword_plan_service.mutate_keyword_plans(81 customer_id=customer_id, operations=[operation]82 )83 84 resource_name = response.results[0].resource_name85 print(f"Created keyword plan with resource name: {resource_name}")86 return resource_name87def _create_keyword_plan_campaign(client, customer_id, keyword_plan):88 """Adds a keyword plan campaign to the given keyword plan.89 Args:90 client: An initialized instance of GoogleAdsClient91 customer_id: A str of the customer_id to use in requests.92 keyword_plan: A str of the keyword plan resource_name this keyword plan93 campaign should be attributed to.create_keyword_plan.94 Returns:95 A str of the resource_name for the newly created keyword plan campaign.96 Raises:97 GoogleAdsException: If an error is returned from the API.98 """99 keyword_plan_campaign_service = client.get_service(100 "KeywordPlanCampaignService"101 )102 operation = client.get_type("KeywordPlanCampaignOperation")103 keyword_plan_campaign = operation.create104#keyword_plan_campaign_name105 keyword_plan_campaign.name = f"Keyword plan campaign {uuid.uuid4()}"106 keyword_plan_campaign.cpc_bid_micros = 1000000107 keyword_plan_campaign.keyword_plan = keyword_plan108 network = client.get_type(109 "KeywordPlanNetworkEnum"110 ).KeywordPlanNetwork.GOOGLE_SEARCH111 keyword_plan_campaign.keyword_plan_network = network112 geo_target = client.get_type("KeywordPlanGeoTarget")113 # Constant for U.S. Other geo target constants can be referenced here:114 # https://developers.google.com/google-ads/api/reference/data/geotargets115 #SG is 2702116 geo_target.geo_target_constant = "geoTargetConstants/2702"117 keyword_plan_campaign.geo_targets.append(geo_target)118 # Constant for English119 language = "languageConstants/1000"120 keyword_plan_campaign.language_constants.append(language)121 response = keyword_plan_campaign_service.mutate_keyword_plan_campaigns(122 customer_id=customer_id, operations=[operation]123 )124 resource_name = response.results[0].resource_name125 print(f"Created keyword plan campaign with resource name: {resource_name}")126 return resource_name127def _create_keyword_plan_ad_group(client, customer_id, keyword_plan_campaign):128 """Adds a keyword plan ad group to the given keyword plan campaign.129 Args:130 client: An initialized instance of GoogleAdsClient131 customer_id: A str of the customer_id to use in requests.132 keyword_plan_campaign: A str of the keyword plan campaign resource_name133 this keyword plan ad group should be attributed to.134 Returns:135 A str of the resource_name for the newly created keyword plan ad group.136 Raises:137 GoogleAdsException: If an error is returned from the API.138 """139 operation = client.get_type("KeywordPlanAdGroupOperation")140 keyword_plan_ad_group = operation.create141 keyword_plan_ad_group.name = f"Keyword plan ad group {uuid.uuid4()}"142 keyword_plan_ad_group.cpc_bid_micros = 2500000143 keyword_plan_ad_group.keyword_plan_campaign = keyword_plan_campaign144 keyword_plan_ad_group_service = client.get_service(145 "KeywordPlanAdGroupService"146 )147 response = keyword_plan_ad_group_service.mutate_keyword_plan_ad_groups(148 customer_id=customer_id, operations=[operation]149 )150 resource_name = response.results[0].resource_name151 print(f"Created keyword plan ad group with resource name: {resource_name}")152 return resource_name153def _create_keyword_plan_ad_group_keywords(client, customer_id, plan_ad_group):154 """Adds keyword plan ad group keywords to the given keyword plan ad group.155 Args:156 client: An initialized instance of GoogleAdsClient157 customer_id: A str of the customer_id to use in requests.158 plan_ad_group: A str of the keyword plan ad group resource_name159 these keyword plan keywords should be attributed to.160 Raises:161 GoogleAdsException: If an error is returned from the API.162 """163 keyword_plan_ad_group_keyword_service = client.get_service(164 "KeywordPlanAdGroupKeywordService"165 )166 operation = client.get_type("KeywordPlanAdGroupKeywordOperation")167 operations = []168 #start editing the keywords here169 operation = client.get_type("KeywordPlanAdGroupKeywordOperation")170 keyword_plan_ad_group_keyword1 = operation.create171 keyword_plan_ad_group_keyword1.text = "mars cruise"172 keyword_plan_ad_group_keyword1.cpc_bid_micros = 2000000173 keyword_plan_ad_group_keyword1.match_type = client.get_type(174 "KeywordMatchTypeEnum"175 ).KeywordMatchType.BROAD176 keyword_plan_ad_group_keyword1.keyword_plan_ad_group = plan_ad_group177 operations.append(operation)178 operation = client.get_type("KeywordPlanAdGroupKeywordOperation")179 keyword_plan_ad_group_keyword2 = operation.create180 keyword_plan_ad_group_keyword2.text = "cheap cruise"181 keyword_plan_ad_group_keyword2.cpc_bid_micros = 1500000182 keyword_plan_ad_group_keyword2.match_type = client.get_type(183 "KeywordMatchTypeEnum"184 ).KeywordMatchType.PHRASE185 keyword_plan_ad_group_keyword2.keyword_plan_ad_group = plan_ad_group186 operations.append(operation)187 operation = client.get_type("KeywordPlanAdGroupKeywordOperation")188 keyword_plan_ad_group_keyword3 = operation.create189 keyword_plan_ad_group_keyword3.text = "jupiter cruise"190 keyword_plan_ad_group_keyword3.cpc_bid_micros = 1990000191 keyword_plan_ad_group_keyword3.match_type = client.get_type(192 "KeywordMatchTypeEnum"193 ).KeywordMatchType.EXACT194 keyword_plan_ad_group_keyword3.keyword_plan_ad_group = plan_ad_group195 operations.append(operation)196 response = keyword_plan_ad_group_keyword_service.mutate_keyword_plan_ad_group_keywords(197 customer_id=customer_id, operations=operations198 )199 for result in response.results:200 print(201 "Created keyword plan ad group keyword with resource name: "202 f"{result.resource_name}"203 )204def _create_keyword_plan_negative_campaign_keywords(205 client, customer_id, plan_campaign206):207 """Adds a keyword plan negative campaign keyword to the given campaign.208 Args:209 client: An initialized instance of GoogleAdsClient210 customer_id: A str of the customer_id to use in requests.211 plan_campaign: A str of the keyword plan campaign resource_name212 this keyword plan negative keyword should be attributed to.213 Raises:214 GoogleAdsException: If an error is returned from the API.215 """216 keyword_plan_negative_keyword_service = client.get_service(217 "KeywordPlanCampaignKeywordService"218 )219 operation = client.get_type("KeywordPlanCampaignKeywordOperation")220 keyword_plan_campaign_keyword = operation.create221 keyword_plan_campaign_keyword.text = "moon walk"222 keyword_plan_campaign_keyword.match_type = client.get_type(223 "KeywordMatchTypeEnum"224 ).KeywordMatchType.BROAD225 keyword_plan_campaign_keyword.keyword_plan_campaign = plan_campaign226 keyword_plan_campaign_keyword.negative = True227 response = keyword_plan_negative_keyword_service.mutate_keyword_plan_campaign_keywords(228 customer_id=customer_id, operations=[operation]229 )230 print(231 "Created keyword plan campaign keyword with resource name: "232 f"{response.results[0].resource_name}"233 )234 # [END add_keyword_plan]235'''236try:237 GA_add_kw_plan(238 client=GoogleAdsClient.load_from_dict(credentials),239 customer_id="1_____")240except GoogleAdsException as ex:241 print(242 f'Request with ID "{ex.request_id}" failed with status '243 f'"{ex.error.code().name}" and includes the following errors:'244 )245 for error in ex.failure.errors:246 print(f' Error with message "{error.message}".')247 if error.location:248 for field_path_element in error.location.field_path_elements:249 print(f"\t\tOn field: {field_path_element.field_name}")250 sys.exit(1)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!