nagasurendra commited on
Commit
22d62df
·
verified ·
1 Parent(s): 3d60223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -78
app.py CHANGED
@@ -33,85 +33,7 @@ def index():
33
  def serve_static(filename):
34
  return send_from_directory('static', filename)
35
 
36
- @app.route('/get_ingredients', methods=['POST'])
37
- def get_ingredients():
38
- dietary_preference = request.json.get('dietary_preference', '').strip().lower()
39
- logging.debug(f"Received dietary preference: {dietary_preference}")
40
 
41
- # Map dietary preference to SOQL condition
42
- if dietary_preference == 'both':
43
- condition = "Category__c = 'both'" # This will fetch both vegetarian and non-vegetarian
44
- else:
45
- preference_map = {
46
- 'vegetarian': "Category__c = 'Veg'",
47
- 'non-vegetarian': "Category__c = 'Non-Veg'"
48
- }
49
- condition = preference_map.get(dietary_preference)
50
-
51
- if not condition:
52
- logging.debug("Invalid dietary preference received.")
53
- return jsonify({"error": "Invalid dietary preference."}), 400
54
-
55
- try:
56
- soql = f"SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE {condition} LIMIT 200"
57
- result = sf.query(soql)
58
- ingredients = [
59
- {"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
60
- for record in result['records'] if 'Name' in record
61
- ]
62
- logging.debug(f"Fetched {len(ingredients)} ingredients.")
63
- return jsonify({"ingredients": ingredients})
64
- except Exception as e:
65
- logging.error(f"Error while fetching ingredients: {str(e)}")
66
- return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
67
-
68
-
69
- @app.route('/get_menu_items', methods=['POST'])
70
- def get_menu_items():
71
- ingredient_names = request.json.get('ingredient_names', '').strip().lower()
72
- logging.debug(f"Received ingredient names: {ingredient_names}")
73
-
74
- # Constructing a SOQL query where Name contains any of the ingredient names
75
- # Split the ingredient names into separate words to match each ingredient
76
- ingredients_list = ingredient_names.split()
77
-
78
- # Create a dynamic WHERE clause to match the ingredient names in the Menu Item names
79
- condition = " OR ".join([f"Name LIKE '%{ingredient}%'" for ingredient in ingredients_list])
80
-
81
- if not condition:
82
- logging.debug("No ingredients received.")
83
- return jsonify({"error": "No valid ingredients provided."}), 400
84
-
85
- try:
86
- soql = f"SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c FROM Menu_Item__c WHERE {condition} LIMIT 200"
87
- result = sf.query(soql)
88
-
89
- menu_items = [
90
- {"name": record['Name'], "price": record.get('Price__c', ''), "description": record.get('Description__c', ''),
91
- "image_url1": record.get('Image1__c', ''), "image_url2": record.get('Image2__c', ''),
92
- "veg_nonveg": record.get('Veg_NonVeg__c', ''), "section": record.get('Section__c', ''),
93
- "total_ordered": record.get('Total_Ordered__c', '')}
94
- for record in result['records'] if 'Name' in record
95
- ]
96
- logging.debug(f"Fetched {len(menu_items)} menu items based on ingredients.")
97
- return jsonify({"menu_items": menu_items})
98
-
99
- except Exception as e:
100
- logging.error(f"Error while fetching menu items: {str(e)}")
101
- return jsonify({"error": f"Failed to fetch menu items: {str(e)}"}), 500
102
-
103
-
104
-
105
- @app.route('/submit_ingredients', methods=['POST'])
106
- def submit_ingredients():
107
- data = request.json
108
- ingredients = data.get('ingredients', [])
109
-
110
- if not ingredients:
111
- return jsonify({'error': 'No ingredients selected'}), 400
112
-
113
- logging.debug(f"Ingredients submitted: {ingredients}")
114
- return jsonify({'success': True})
115
 
116
  if __name__ == '__main__':
117
  app.run(debug=True, host='0.0.0.0', port=7860)
 
33
  def serve_static(filename):
34
  return send_from_directory('static', filename)
35
 
 
 
 
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  if __name__ == '__main__':
39
  app.run(debug=True, host='0.0.0.0', port=7860)