-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (37 loc) · 1.08 KB
/
app.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
import os
from datetime import datetime
import json
import pymongo
import os
import bd_config
from flask import Flask, session, render_template, request, jsonify
#from flask_socketio import SocketIO, emit
from GameEnv import GameEnv
from ModelBuilder import *
bd_config.init()
LOAD_DB = True
app = Flask(__name__)
#app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
#socketio = SocketIO(app)
#landing page
@app.route("/")
def index():
return render_template("index.html")
@app.route("/machine")
def machine():
return render_template("machine.html")
@app.route("/game_data", methods=['POST'])
def game_data():
data = request.get_json()
if (LOAD_DB):
connectTo = 'final_project'
client = pymongo.MongoClient(f"mongodb+srv://{bd_config.USERNAME}:{bd_config.PASSWORD}@bricluster.yskth.mongodb.net/{connectTo}?retryWrites=true&w=majority")
db = client.final_project
collection = db.state_action
collection.insert_many(data)
client.close()
else:
print(data)
return "OK", 200
if __name__ == "__main__":
app.run(debug=True)