-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (34 loc) · 1.04 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
# imports
import os
import json
from bottle import route, run, request
from command import Command
from coordinate import Coordinate
# routes
@route('/')
def index():
return "Placeholder for Python app"
@route('/command',method='POST')
def index():
status = json.loads(request.body.read())
if (status["RoundNumber"] == 0) :
print "New game, I should probably reset"
return json.dumps(createCommands())
def createCommands():
cmdArray = []
cmdArray.append(createCommand(1).__dict__)
cmdArray.append(createCommand(2).__dict__)
return cmdArray
def createCommand(vesselid):
cmd = Command()
cmd.vesselid = vesselid
cmd.coordinate = createCoordinate(1, 1).__dict__
return cmd
def createCoordinate(x, y):
coordinate = Coordinate()
coordinate.X = x
coordinate.Y = y
return coordinate
# start server and listen for requests
# for Cloud9 run(host=os.environ["OPENSHIFT_DIY_IP"], port=int(os.environ["PORT"]), debug=True)
run(host='0.0.0.0', port=int(os.environ["PORT"]), debug=True)