Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate negative keywords list to GBB team #907

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"