-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (43 loc) · 1.29 KB
/
app.py
File metadata and controls
52 lines (43 loc) · 1.29 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import requests
import json
from flask import Flask, render_template, url_for
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app)
apiKey = os.getenv("API_KEY")
@app.route("/", methods=("GET", "POST"))
def index():
return render_template("index.html")
@socketio.on('submit_form')
def handle_form_submission(data):
brainId = data['brainId']
thtName = data['thtName']
kind = 1
thtLabel = data['thtLabel']
typeId = None
srcThtId = data['srcThtId']
relation = 1
acType = 0
url = f'https://api.bra.in/thoughts/{brainId}'
headers = {
'Authorization': f'Bearer {apiKey}',
'Content-Type': 'application/json'
}
body = {
'name': thtName,
'kind': kind,
'label': thtLabel,
'typeId': typeId,
'sourceThoughtId': srcThtId,
'relation': relation,
'acType': acType
}
response = requests.post(url, headers=headers, json=body)
if response.status_code == 200:
response_data = response.json()
newThoughtId = response_data
socketio.emit('form_response', {'message': f'Success! New Thought ID: {newThoughtId}'})
else:
errorMessage = response.text
socketio.emit('form_response', {'message': f'Error: {response.text}'})