Spaces:
Sleeping
Sleeping
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 | |
def index(): | |
return render_template('index.html') | |
def serve_static(filename): | |
return send_from_directory('static', filename) | |
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) |