2. 智能推荐系统 - 基于用户购买记录的推荐: ```python def recommend_recipes(user_purchases): 获取用户购买的食材 ingredients = [item[name] for item in user_purchases]
查询包含这些食材的菜谱 recommended = [] for recipe in all_recipes: recipe_ingredients = [i[name] for i in recipe[ingredients]] if any(ing in recipe_ingredients for ing in ingredients): recommended.append(recipe)
按匹配度排序 recommended.sort(key=lambda x: len(set(ingredients) & set([i[name] for i in x[ingredients]])), reverse=True) return recommended[:5] 返回前5个推荐 ```
3. 烹饪步骤引导 - 交互式步骤展示: ```html
1
准备食材
将番茄洗净切块,鸡蛋打入碗中...
```
4. 食材清单生成 - 根据菜谱生成购物清单: ```javascript function generateShoppingList(recipeId) { const recipe = getRecipeById(recipeId); let list = {};