| from flask import Flask, render_template, request, jsonify |
| from simple_salesforce import Salesforce |
|
|
| |
| app = Flask(__name__) |
|
|
| |
| sf = Salesforce(username='your_username', password='your_password', security_token='your_token') |
|
|
| |
| @app.route('/') |
| def index(): |
| return render_template('index.html') |
|
|
| |
| @app.route('/get_recipes', methods=['GET']) |
| def get_recipes(): |
| ingredients = request.args.get('ingredients').split(',') |
| normalized_ingredients = [i.strip().lower() for i in ingredients] |
|
|
| |
| 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) |
|
|