-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
70 lines (53 loc) · 1.75 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import os
import mysql.connector
from dotenv import load_dotenv
from flask import Flask, request
from flask_cors import CORS
import config
from game import Game
load_dotenv()
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
config.conn = mysql.connector.connect(
host=os.environ.get('HOST'),
port=int(os.environ.get('PORT')),
database=os.environ.get('DB_NAME'),
user=os.environ.get('DB_USER'),
password=os.environ.get('DB_PASS'),
autocommit=True,
ssl_disabled=True,
)
def fly(id, dest, consumption=0, player=None):
if id == 0:
game = Game(0, dest, consumption, player)
else:
game = Game(id, dest, consumption)
game.location[0].fetch_magics(game)
magicLoc = game.location[0].set_magic_airports()
for m in magicLoc:
game.location.append(m)
json_data = json.dumps(game, default=lambda o: o.__dict__, indent=4)
return json_data
# http://127.0.0.1:7000/flyto?game=VAFyWkaMC4H1jWxR44Tl&dest=ESCF&consumption=246
@app.route('/flyto')
def flyto():
args = request.args
id = args.get("game")
dest = args.get("dest")
consumption = args.get("consumption")
json_data = fly(id, dest, consumption)
print("Called flyto endpoint at http:localhost:7000/flyto/")
return json_data
# http://127.0.0.1:7000/newgame?player=Remy&loc=LFDZ
@app.route('/newgame')
def newgame():
args = request.args
player = args.get("player")
dest = args.get("loc")
json_data = fly(0, dest, 0, player)
return json_data
if __name__ == '__main__':
# app.run(use_reloader=True, host='127.0.0.1', port=7000)
app.run(use_reloader=True, host='0.0.0.0', port=int(os.environ.get('PORT', 7000)))