File size: 1,223 Bytes
8bd20d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
from simple_salesforce import Salesforce

# Initialize Flask App
app = Flask(__name__)

# Initialize Salesforce connection
sf = Salesforce(username='your_username', password='your_password', security_token='your_token')

# Route for the home page
@app.route('/')
def index():
    return render_template('index.html')

# Route to handle user input and get recipes from Salesforce
@app.route('/get_recipes', methods=['GET'])
def get_recipes():
    ingredients = request.args.get('ingredients').split(',')  # Get comma-separated ingredients
    normalized_ingredients = [i.strip().lower() for i in ingredients]

    # Query Salesforce to find matching recipes
    query = f"SELECT Name, Description, Ingredients__c FROM Recipe WHERE Ingredients__c LIKE '%{'% OR Ingredients__c LIKE '.join(normalized_ingredients)}%'"
    recipes = sf.query(query)

    result = []
    for recipe in recipes['records']:
        result.append({
            'name': recipe['Name'],
            'description': recipe['Description'],
            'ingredients': recipe['Ingredients__c'].split(','),
        })

    return jsonify(result)

if __name__ == '__main__':
    app.run(debug=True)