forked from JimVincentW/bt-reviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
29 lines (22 loc) · 886 Bytes
/
api.py
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
from flask import Flask, jsonify, request
import api_main as main # import your refactored main script
import logging
app = Flask(__name__)
# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@app.route('/receive-url', methods=['POST'])
def receive_url():
try:
data = request.json
url = data.get('url')
if not url:
return jsonify({"error": "No URL provided"}), 400
# Call your refactored main function that processes a URL
results = main.process_url(url)
except Exception as e:
logger.exception("Failed to process URL.") # This will log the full exception traceback
return jsonify({"error": str(e)}), 500
return jsonify({"status": "success", "data": results}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)