Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,24 +41,9 @@ def get_ingredients():
|
|
41 |
if dietary_preference == 'vegetable':
|
42 |
logging.debug("Fetching ingredients for Vegetables...")
|
43 |
soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Veg' LIMIT 200"
|
44 |
-
elif dietary_preference in ['chicken', 'beef', 'lamb']:
|
45 |
-
logging.debug(f"Fetching ingredients for
|
46 |
-
# Fallback: Fetch all non-veg ingredients and filter manually (adjust if a specific field exists)
|
47 |
soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Non-Veg' LIMIT 200"
|
48 |
-
# Manual filtering (example; replace with actual field if available)
|
49 |
-
try:
|
50 |
-
result = sf.query(soql)
|
51 |
-
ingredients = [
|
52 |
-
{"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
|
53 |
-
for record in result['records'] if 'Name' in record
|
54 |
-
]
|
55 |
-
# Simulate filtering based on dietary_preference (e.g., if a field like 'Type__c' existed)
|
56 |
-
# For now, return all non-veg ingredients (update with correct logic)
|
57 |
-
logging.debug(f"Fetched {len(ingredients)} ingredients.")
|
58 |
-
return jsonify({"ingredients": ingredients})
|
59 |
-
except Exception as e:
|
60 |
-
logging.error(f"Error while fetching ingredients: {str(e)}")
|
61 |
-
return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
|
62 |
else:
|
63 |
logging.debug("Invalid dietary preference received.")
|
64 |
return jsonify({"error": "Invalid dietary preference."}), 400
|
@@ -75,17 +60,13 @@ def get_ingredients():
|
|
75 |
logging.error(f"Error while fetching ingredients: {str(e)}")
|
76 |
return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
|
77 |
|
78 |
-
@app.route('/
|
79 |
-
def
|
80 |
-
|
81 |
-
logging.debug(f"Received
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
soql = "SELECT Item_Name__c, Image_URL__c FROM Menu_Item__c WHERE Category__c = 'Fish' LIMIT 200"
|
86 |
-
else:
|
87 |
-
logging.debug("Invalid category received.")
|
88 |
-
return jsonify({"error": "Invalid category."}), 400
|
89 |
|
90 |
try:
|
91 |
result = sf.query(soql)
|
|
|
41 |
if dietary_preference == 'vegetable':
|
42 |
logging.debug("Fetching ingredients for Vegetables...")
|
43 |
soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Veg' LIMIT 200"
|
44 |
+
elif dietary_preference in ['chicken', 'beef', 'lamb', 'non-vegetarian']:
|
45 |
+
logging.debug(f"Fetching ingredients for Non-Vegetarian...")
|
|
|
46 |
soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Non-Veg' LIMIT 200"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
logging.debug("Invalid dietary preference received.")
|
49 |
return jsonify({"error": "Invalid dietary preference."}), 400
|
|
|
60 |
logging.error(f"Error while fetching ingredients: {str(e)}")
|
61 |
return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
|
62 |
|
63 |
+
@app.route('/get_menu_items_by_ingredients', methods=['POST'])
|
64 |
+
def get_menu_items_by_ingredients():
|
65 |
+
ingredients = request.json.get('ingredients', '').strip().lower()
|
66 |
+
logging.debug(f"Received ingredients: {ingredients}")
|
67 |
|
68 |
+
# Assuming Menu_Items object has an Ingredients__c field to match with selected ingredients
|
69 |
+
soql = f"SELECT Item_Name__c, Image_URL__c FROM Menu_Items__c WHERE Ingredients__c LIKE '%{ingredients}%' LIMIT 200"
|
|
|
|
|
|
|
|
|
70 |
|
71 |
try:
|
72 |
result = sf.query(soql)
|