Skip to content

Commit

Permalink
Integrate negative keywords list to GBB team
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic committed Aug 27, 2024
1 parent 71954ae commit 11a071e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
36 changes: 36 additions & 0 deletions captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CampaignCallouts,
CampaignCriterion,
CampaignLanguageCriterion,
CampaignSharedSet,
GeoTargetCriterion,
RemoveResource,
)
Expand Down Expand Up @@ -275,6 +276,33 @@ def _create_negative_campaign_keywords(
)


def _add_negative_campaign_keywords_lists(
customer_id: str,
login_customer_id: Optional[str],
campaign_id: str,
keywords_df: pd.DataFrame,
context: GoogleSheetsTeamContext,
) -> None:
negative_campaign_keywords_lists = keywords_df[
(keywords_df["Level"] == "Campaign List") & (keywords_df["Negative"])
]
for _, row in negative_campaign_keywords_lists.iterrows():
model = CampaignSharedSet(
login_customer_id=login_customer_id,
customer_id=customer_id,
campaign_id=campaign_id,
shared_set_name=row["Keyword"],
)
google_ads_post(
user_id=context.user_id,
conv_id=context.conv_id,
recommended_modifications_and_answer_list=context.recommended_modifications_and_answer_list,
model=model,
endpoint="/add-shared-set-to-campaign",
already_checked_clients_approval=True,
)


def _create_negative_ad_group_keywords(
customer_id: str,
login_customer_id: Optional[str],
Expand Down Expand Up @@ -673,6 +701,14 @@ def _setup_campaign(
(keywords_df["Campaign Name"] == campaign_name)
]

_add_negative_campaign_keywords_lists(
customer_id=customer_id,
login_customer_id=login_customer_id,
campaign_id=campaign_id,
keywords_df=all_campaign_keywords,
context=context,
)

_create_negative_campaign_keywords(
customer_id=customer_id,
login_customer_id=login_customer_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
GoogleAdsResources,
GoogleSheetsTeamContext,
ResourceCreationResponse,
_add_negative_campaign_keywords_lists,
_check_if_both_include_and_exclude_language_values_exist,
_check_mandatory_columns,
_get_alredy_existing_campaigns,
Expand Down Expand Up @@ -814,3 +815,32 @@ def test_update_callouts(
mock_requests_post.assert_called_once()
call = mock_requests_post.call_args_list[0]
assert call[1]["json"]["callouts"] == ["Free cancellation", "Return tickets"]

def test_add_negative_campaign_keywords_lists(
self,
mock_get_login_url: Iterator[None],
mock_requests_post: Iterator[Any],
) -> None:
keywords_df = pd.DataFrame(
{
"Campaign Name": ["My Campaign", "My Campaign"],
"Ad Group Name": ["My Campaign Ad Group", "My Campaign Ad Group"],
"Match Type": ["Exact", "Exact"],
"Keyword": ["Svi autobusni polasci", "my-list"],
"Level": [None, "Campaign List"],
"Negative": [False, True],
}
)

campaign_id = "12345"
_add_negative_campaign_keywords_lists(
customer_id=self.customer_id,
login_customer_id=self.login_customer_id,
keywords_df=keywords_df,
campaign_id=campaign_id,
context=self.context,
)

mock_requests_post.assert_called_once()
call = mock_requests_post.call_args_list[0]
assert call[1]["json"]["shared_set_name"] == "my-list"

0 comments on commit 11a071e

Please sign in to comment.