Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, send_from_directory, request, jsonify
|
| 2 |
+
from simple_salesforce import Salesforce
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
app = Flask(__name__, template_folder='templates', static_folder='static')
|
| 12 |
+
|
| 13 |
+
def get_salesforce_connection():
|
| 14 |
+
try:
|
| 15 |
+
sf = Salesforce(
|
| 16 |
+
username=os.getenv('SFDC_USERNAME'),
|
| 17 |
+
password=os.getenv('SFDC_PASSWORD'),
|
| 18 |
+
security_token=os.getenv('SFDC_SECURITY_TOKEN'),
|
| 19 |
+
domain=os.getenv('SFDC_DOMAIN', 'login')
|
| 20 |
+
)
|
| 21 |
+
return sf
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"Error connecting to Salesforce: {e}")
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
sf = get_salesforce_connection()
|
| 27 |
+
|
| 28 |
+
@app.route('/')
|
| 29 |
+
def index():
|
| 30 |
+
return render_template('index.html')
|
| 31 |
+
|
| 32 |
+
@app.route('/static/<path:filename>')
|
| 33 |
+
def serve_static(filename):
|
| 34 |
+
return send_from_directory('static', filename)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if __name__ == '__main__':
|
| 39 |
+
app.run(debug=True, host='0.0.0.0', port=7860)
|