diff --git a/google_sheets/app.py b/google_sheets/app.py index e94f2a8..134d843 100644 --- a/google_sheets/app.py +++ b/google_sheets/app.py @@ -314,6 +314,9 @@ async def get_all_sheet_titles( MANDATORY_KEYWORD_TEMPLATE_COLUMNS = [ "Keyword", + "Keyword Match Type", + "Level", + "Negative", ] diff --git a/google_sheets/data_processing/processing.py b/google_sheets/data_processing/processing.py index 24a78e5..4c97ac0 100644 --- a/google_sheets/data_processing/processing.py +++ b/google_sheets/data_processing/processing.py @@ -79,11 +79,24 @@ def process_data_f( if target_resource == "ad": new_row["Final URL"] = station["Final Url"] + elif ( + target_resource == "keyword" + and new_row["Negative"] + and new_row["Negative"].lower() == "true" + ): + new_row["Match Type"] = new_row["Keyword Match Type"] + + if new_row["Level"] == "Campaign": + new_row["Ad Group Name"] = None final_df = pd.concat( [final_df, pd.DataFrame([new_row])], ignore_index=True ) + if target_resource == "keyword": + final_df = final_df.drop(columns=["Keyword Match Type"]) + final_df = final_df.drop_duplicates(ignore_index=True) + final_df = final_df.sort_values( by=["Campaign Name", "Ad Group Name"], ignore_index=True ) @@ -99,6 +112,8 @@ def process_data_f( MAX_HEADLINE_LENGTH = 30 MAX_DESCRIPTION_LENGTH = 90 +MAX_PATH_LENGTH = 15 + def _validate_output_data_ad(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901 df["Issues"] = "" @@ -152,9 +167,14 @@ def _validate_output_data_ad(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901 f"Description length should be less than {MAX_DESCRIPTION_LENGTH} characters, found {len(description)} in column {description_column}.\n" ) - # TODO: Check for the final URL - # if not row["Final URL"]: - # df.loc[index, "Issues"] += "Final URL is missing.\n" + for path in ["Path 1", "Path 2"]: + if row[path] and len(row[path]) > MAX_PATH_LENGTH: + df.loc[index, "Issues"] += ( + f"{path} length should be less than {MAX_PATH_LENGTH} characters, found {len(row[path])}.\n" + ) + + if not row["Final URL"]: + df.loc[index, "Issues"] += "Final URL is missing.\n" if not df["Issues"].any(): df = df.drop(columns=["Issues"]) diff --git a/tests/app/test_app.py b/tests/app/test_app.py index 4bd5c77..a3401e9 100644 --- a/tests/app/test_app.py +++ b/tests/app/test_app.py @@ -228,8 +228,12 @@ class TestProcessData: values=[ [ "Keyword", + "Keyword Match Type", + "Level", + "Negative", ], - ["Keyword A"], + ["Keyword A", "Exact", None, "False"], + ["Keyword N", "Broad", "Campaign", "True"], ] ), GoogleSheetValues( @@ -257,18 +261,32 @@ class TestProcessData: "Ad Group Name", "Match Type", "Keyword", + "Level", + "Negative", ], [ "India - Delhi - Mumbai", "Delhi - Mumbai", "Exact", "Keyword A", + None, + "False", ], [ "India - Delhi - Mumbai", "Mumbai - Delhi", "Exact", "Keyword A", + None, + "False", + ], + [ + "India - Delhi - Mumbai", + None, + "Broad", + "Keyword N", + "Campaign", + "True", ], ], ), diff --git a/tests/data_processing/test_processing.py b/tests/data_processing/test_processing.py index 6bf6d7a..f1cc9e6 100644 --- a/tests/data_processing/test_processing.py +++ b/tests/data_processing/test_processing.py @@ -186,6 +186,9 @@ def test_validate_output_data(issues_column: Optional[List[str]]) -> None: "Headline 3": ["H3", "H3", "H3", ""], "Description 1": ["D1", "D1", "D2", "D3"], "Description 2": ["D1", "D1", "D3", ""], + "Path 1": ["P1", "P1", "P1", "P1"], + "Path 2": ["P2", "P2", "P2", "P2"], + "Final URL": ["URL", "URL", "URL", "URL"], } ) result = validate_output_data(df, "ad")