Yaswanth56 commited on
Commit
a2f1a4d
·
verified ·
1 Parent(s): cf231bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -1
app.py CHANGED
@@ -1,7 +1,12 @@
1
- from flask import Flask, render_template, send_from_directory
 
2
 
3
  app = Flask(__name__, template_folder='templates', static_folder='static')
4
 
 
 
 
 
5
  @app.route('/')
6
  def index():
7
  return render_template('index.html')
@@ -10,5 +15,32 @@ def index():
10
  def serve_static(filename):
11
  return send_from_directory('static', filename)
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  if __name__ == '__main__':
14
  app.run(debug=True, host='0.0.0.0', port=7860)
 
1
+ from flask import Flask, render_template, send_from_directory, request, jsonify
2
+ import requests
3
 
4
  app = Flask(__name__, template_folder='templates', static_folder='static')
5
 
6
+ # Salesforce connection details (replace with your credentials)
7
+ SFDC_INSTANCE_URL = "https://yourinstance.my.salesforce.com" # Replace with your Salesforce instance URL
8
+ SFDC_ACCESS_TOKEN = "your_access_token" # Replace with your Salesforce access token
9
+
10
  @app.route('/')
11
  def index():
12
  return render_template('index.html')
 
15
  def serve_static(filename):
16
  return send_from_directory('static', filename)
17
 
18
+ @app.route('/get_ingredients', methods=['POST'])
19
+ def get_ingredients():
20
+ dietary_preference = request.json.get('dietary_preference', '').lower()
21
+
22
+ # Salesforce SOQL query based on dietary preference
23
+ if dietary_preference == 'veg':
24
+ soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c WHERE Category__c IN ('Veg', 'Both') LIMIT 100"
25
+ elif dietary_preference == 'non-vegetarian':
26
+ soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c WHERE Category__c IN ('Non-Veg', 'Both') LIMIT 100"
27
+ else:
28
+ soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c LIMIT 100" # Default case
29
+
30
+ headers = {
31
+ "Authorization": f"Bearer {SFDC_ACCESS_TOKEN}",
32
+ "Content-Type": "application/json"
33
+ }
34
+ url = f"{SFDC_INSTANCE_URL}/services/data/v57.0/query/?q={soql}"
35
+
36
+ try:
37
+ response = requests.get(url, headers=headers)
38
+ response.raise_for_status()
39
+ data = response.json()
40
+ ingredients = [record['Sector_Detail_Name__c'] for record in data['records'] if 'Sector_Detail_Name__c' in record]
41
+ return jsonify({"ingredients": ingredients})
42
+ except requests.exceptions.RequestException as e:
43
+ return jsonify({"error": str(e)}), 500
44
+
45
  if __name__ == '__main__':
46
  app.run(debug=True, host='0.0.0.0', port=7860)