def update_attributes()

in projects/conversational-commerce-agent/data-ingestion/food_to_retail_search.py [0:0]


def update_attributes(source_obj) -> dict:
    """
    Update site level attribute controls
    Args:
        source_obj: source product attribute controls
    Returns:
        dict: updated attribute controls
    """
    target_obj = {
        "attributes" : {}
    }

    item_name = source_obj["menuItemName"].lower()
    item_desc = source_obj["menuItemDescription"].lower()

    if ("vegan" in item_name or
        "vegan" in item_desc):
        target_obj["attributes"]["Vegan"] = {
            "text": ["yes"],
            "searchable": True,
            "indexable": True
        }
    else:
        target_obj["attributes"]["Vegan"] = {
            "text": ["no"],
            "searchable": True,
            "indexable": True
        }
    grill_items = ["chicken",
                   "beef",
                   "pork",
                   "seafood",
                   "fish",
                   "shrimp",
                   "duck",
                   "steak"]
    # any(item in string for item in array)
    if (any(item in item_name for item in grill_items) or
        any(item in item_desc for item in grill_items)):
        target_obj["attributes"]["Tags"] = {
            "text": ["grill"],
            "searchable": True,
            "indexable": True
        }
    if ("gluten free" in item_name.replace("-", " ") or
        "gluten free" in item_desc.replace("-", " ")):
        if target_obj["attributes"].get("Tags", None) is not None:
            target_obj["attributes"]["Tags"]["text"].append("gluten free")
        else:
            target_obj["attributes"]["Tags"] = {
                "text": ["gluten free"],
                "searchable": True,
                "indexable": True
            }

    return target_obj["attributes"]