File size: 1,931 Bytes
a2f1a4d
 
4be2e38
c32c1af
4be2e38
a2f1a4d
 
 
 
4be2e38
 
 
 
c32c1af
 
 
4be2e38
a2f1a4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4be2e38
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from flask import Flask, render_template, send_from_directory, request, jsonify
import requests

app = Flask(__name__, template_folder='templates', static_folder='static')

# Salesforce connection details (replace with your credentials)
SFDC_INSTANCE_URL = "https://yourinstance.my.salesforce.com"  # Replace with your Salesforce instance URL
SFDC_ACCESS_TOKEN = "your_access_token"  # Replace with your Salesforce access token

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/static/<path:filename>')
def serve_static(filename):
    return send_from_directory('static', filename)

@app.route('/get_ingredients', methods=['POST'])
def get_ingredients():
    dietary_preference = request.json.get('dietary_preference', '').lower()
    
    # Salesforce SOQL query based on dietary preference
    if dietary_preference == 'veg':
        soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c WHERE Category__c IN ('Veg', 'Both') LIMIT 100"
    elif dietary_preference == 'non-vegetarian':
        soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c WHERE Category__c IN ('Non-Veg', 'Both') LIMIT 100"
    else:
        soql = "SELECT Sector_Detail_Name__c FROM Sector_Detail__c LIMIT 100"  # Default case

    headers = {
        "Authorization": f"Bearer {SFDC_ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    url = f"{SFDC_INSTANCE_URL}/services/data/v57.0/query/?q={soql}"
    
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        ingredients = [record['Sector_Detail_Name__c'] for record in data['records'] if 'Sector_Detail_Name__c' in record]
        return jsonify({"ingredients": ingredients})
    except requests.exceptions.RequestException as e:
        return jsonify({"error": str(e)}), 500

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=7860)