-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (54 loc) · 2.06 KB
/
main.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO, join_room, send, leave_room, emit
import requests
from requests.exceptions import ConnectionError
import os
import json
app = Flask(__name__)
app.config['SECRET_KEY'] = ''
socketio = SocketIO(app, cors_allowed_origins="*")
endpoints = {"room": ["https://hey.i.tgcloud.io:14240/gsqlserver/gsql/codecheck", "tigergraph", "Password"]} # Stores Box credentials for every room
link = "hey"
username = "tigergraph"
password = "Password"
graphname = "graphname"
@app.route('/')
def sessions():
return render_template('index.html')
# Add the user to their specific room, and stores the box credentials in the dictionary
@socketio.on('join')
def join(data):
room = data['room']
room = str(room)
box_link = data["link"]
box_username = data["username"]
box_password = data["password"]
box_graphname = data["graphname"]
join_room(room)
if room not in endpoints:
endpoints[room] = [box_link, box_username, box_password, box_graphname]
emit('joinedroom', "joinedroom", room=room, broadcast=True, include_self=False)
# Removes the user from the room
@socketio.on('leave')
def on_leave(data):
room = data['room']
leave_room(room)
# Triggers everytime textarea changes, emits the updated textarea to everyone in the room and also emits the Errors/Warnings
@socketio.on("send message")
def message(data):
print(link, username, password)
room = data['room']
code = {
"code": data['message'],
"graph": endpoints[room][3]
}
box_link = endpoints[room][0]
box_username = endpoints[room][1]
box_password = endpoints[room][2]
# Making a request to the box specific codecheck endpoint
response = requests.post(box_link,
json=code, auth=(box_username, box_password))
emit('broadcast message', data['message'], room=room, broadcast=True, include_self=False)
emit('broadcast errors', response.json(), room=room)
if __name__ == '__main__':
app.run(debug=True)