-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (35 loc) · 1.1 KB
/
app.py
File metadata and controls
45 lines (35 loc) · 1.1 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
from flask import Flask, json, Response, redirect
from flask_cors import CORS
import os
import random
import json
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# allows redirects
CORS(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:G8AR7Cseu5bTh9pPttcX@localhost/flowgames'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
# databse model
class Flow_Games(db.Model):
__tablename__ = 'games'
id = db.Column(db.Integer, primary_key=True, unique=True)
game_board = db.Column(db.JSON)
def __repr__(self):
return f'<Board: {self.id} {self.game_board}>'
@app.route('/')
def index():
return '<h1>Hello World!</h1>'
@app.route('/users/<name>')
def user(name):
return '<h1>Hello, {}!</h1>'.format(name)
@app.route('/play')
def choose_game():
game_num = random.randint(1, 5)
return redirect(f'/game/{game_num}')
@app.route('/game/<num>')
def game(num):
game = json.dumps(Flow_Games.query.filter_by(id=num).first().game_board)
return Response(game, mimetype='application/json')
if __name__ == "__main__":
app.run()