Yaswanth56 commited on
Commit
51d39c9
·
verified ·
1 Parent(s): 8c53fce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -45
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from flask import Flask, render_template, send_from_directory, request, jsonify
2
  from simple_salesforce import Salesforce
3
  from dotenv import load_dotenv
4
  import os
@@ -35,10 +35,6 @@ sf = get_salesforce_connection()
35
  def index():
36
  return render_template('index.html')
37
 
38
- @app.route('/static/<path:filename>')
39
- def serve_static(filename):
40
- return send_from_directory('static', filename)
41
-
42
  @app.route('/get_ingredients', methods=['POST'])
43
  def get_ingredients():
44
  global sf
@@ -59,7 +55,7 @@ def get_ingredients():
59
 
60
  try:
61
  # Construct the base query
62
- soql = "SELECT Name, Image_URL__c, Category__c FROM Sector_Detail__c"
63
  if condition:
64
  soql += f" WHERE {condition}"
65
  soql += " LIMIT 200"
@@ -67,51 +63,14 @@ def get_ingredients():
67
  logger.info(f"Executing SOQL query: {soql}")
68
  result = sf.query(soql)
69
  ingredients = [
70
- {"name": record['Name'], "image_url": record.get('Image_URL__c', ''), "category": record.get('Category__c', '')}
71
  for record in result['records'] if 'Name' in record
72
  ]
73
- logger.info(f"Fetched {len(ingredients)} ingredients: {[ing['name'] + ' (' + ing['category'] + ')' for ing in ingredients]}")
74
  return jsonify({"ingredients": ingredients})
75
  except Exception as e:
76
  logger.error(f"Failed to fetch ingredients: {str(e)}")
77
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
78
 
79
- @app.route('/get_menu_items_by_ingredients', methods=['POST'])
80
- def get_menu_items_by_ingredients():
81
- global sf
82
- if not sf:
83
- sf = get_salesforce_connection()
84
- if not sf:
85
- return jsonify({"error": "Failed to connect to Salesforce"}), 500
86
-
87
- ingredients = request.json.get('ingredients', '').strip().lower()
88
- logger.info(f"Received ingredients: {ingredients}")
89
-
90
- # Assuming Menu_Items__c object has an Ingredients__c field to match with selected ingredients
91
- soql = f"SELECT Item_Name__c, Image_URL__c FROM Menu_Items__c WHERE Ingredients__c LIKE '%{ingredients}%' LIMIT 200"
92
-
93
- try:
94
- result = sf.query(soql)
95
- menu_items = [
96
- {"name": record['Item_Name__c'], "image_url": record.get('Image_URL__c', '')}
97
- for record in result['records'] if 'Item_Name__c' in record
98
- ]
99
- logger.info(f"Fetched {len(menu_items)} menu items.")
100
- return jsonify({"menu_items": menu_items})
101
- except Exception as e:
102
- logger.error(f"Error while fetching menu items: {str(e)}")
103
- return jsonify({"error": f"Failed to fetch menu items: {str(e)}"}), 500
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
- logger.info(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)
 
1
+ from flask import Flask, render_template, request, jsonify
2
  from simple_salesforce import Salesforce
3
  from dotenv import load_dotenv
4
  import os
 
35
  def index():
36
  return render_template('index.html')
37
 
 
 
 
 
38
  @app.route('/get_ingredients', methods=['POST'])
39
  def get_ingredients():
40
  global sf
 
55
 
56
  try:
57
  # Construct the base query
58
+ soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c"
59
  if condition:
60
  soql += f" WHERE {condition}"
61
  soql += " LIMIT 200"
 
63
  logger.info(f"Executing SOQL query: {soql}")
64
  result = sf.query(soql)
65
  ingredients = [
66
+ {"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
67
  for record in result['records'] if 'Name' in record
68
  ]
69
+ logger.info(f"Fetched {len(ingredients)} ingredients: {ingredients}")
70
  return jsonify({"ingredients": ingredients})
71
  except Exception as e:
72
  logger.error(f"Failed to fetch ingredients: {str(e)}")
73
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  if __name__ == '__main__':
76
  app.run(debug=True, host='0.0.0.0', port=7860)