-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_python_server.py
More file actions
47 lines (34 loc) · 1014 Bytes
/
socket_python_server.py
File metadata and controls
47 lines (34 loc) · 1014 Bytes
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
from discord import message
from flask.helpers import make_response
from flask_socketio import SocketIO
import string
import random
from flask import Flask
from dotenv import dotenv_values
from flask_cors import CORS, cross_origin
config = dotenv_values(".env")
def generateRandomString(n):
letters = string.ascii_lowercase
return "".join(random.choice(letters) for i in range(n))
app = Flask(__name__)
CORS(app)
app.config["SECRET_KEY"] = generateRandomString(10)
socketio = SocketIO(app, cors_allowed_origins="http://localhost:3000")
@app.route("/socket.io")
@cross_origin
def socketIOEndpoint():
return "success"
@socketio.on("send_message")
def handleMessageSend(
json,
):
returningMessage = json
returningMessage["answer"]["user_has_voted"] = False
socketio.emit("recieve_mesage", json)
@socketio.on("upvote")
def handleUpvoteSend(
json,
):
socketio.emit("upvote", json)
if __name__ == "__main__":
socketio.run(app, debug=True, port=config["SOCKET_PORT"])