-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.py
103 lines (84 loc) · 2.5 KB
/
server.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
'''
A Server to respond to ajax requests from the gmm-up javascript front end.
'''
from flask import Flask, jsonify,send_from_directory,request
import zoning
import WhereWeMeet
#Set up flask server
app = Flask(__name__,static_folder='static')
#name the apps this server can provide
apps = ["zoning","travel-time"]
myapp = None #Initial app loaded. None right now
def get_app(appstring):
'''Set which app is going to be responding to requests'''
if appstring == 'zoning':
return zoning
elif appstring == 'travel-time':
return WhereWeMeet
#an example json response, incase you care to see.
json_response = {
'polygon':
{'L57':
{'strokeColor':'#262626',
'fillColor':'#A6CEE3',
'fillOpacity':0.5,
'paths': #paths = All of the sets of polygons
[ #paths[0] = One set of polygons, whole and holes
[ #paths[0][0] = one set of polygons
[[30.265631, -97.720796], #paths[0][0][0]= an individual polygon
[30.264739, -97.721215], #paths[0][0][0][0] =
[30.262647, -97.722196],
[30.263278, -97.724052],
[30.266618, -97.722513],
[30.265947, -97.720648],
[30.265631, -97.720796]],
[[30.263555, -97.722405],
[30.263457, -97.722083],
[30.263671, -97.721991],
[30.263769, -97.722323],
[30.263555, -97.722405]]
]
]
}
}
}
@app.route("/")
def hello():
with open('index.html','rb') as f:
return f.read()
@app.route("/apps/")
def give_apps():
'''Just return the list of apps that are available'''
return jsonify({'apps':apps})
@app.route("/data/",methods=['GET', 'POST'])
def give_data():
try:
qtype = request.args['type']
appstring = request.args['app']
except KeyError:
return None
else:
myapp = get_app(appstring)
return jsonify(myapp.data(qtype))
@app.route("/app/",methods=['GET','POST'])
def give_options():
try:
appstring = request.args['app']
except KeyError:
return None
else:
myapp = get_app(appstring)
return jsonify(myapp.options())
@app.route('/javascripts/<path:filename>')
def send_js(filename):
with open('./javascripts/%s'%filename,'rb') as f:
return f.read()
@app.route('/stylesheets/<path:filename>')
def send_css(filename):
with open('./stylesheets/%s'%filename,'rb') as f:
return f.read()
if __name__ == "__main__":
import commands
local_ip = commands.getoutput("/sbin/ip addr").split("\n")[10].strip().split(' ')[1].split('/')[0]
app.run(local_ip,debug=True)