/
__init__.py
68 lines (47 loc) · 1.56 KB
/
__init__.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
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask import render_template, url_for, redirect
from flask import make_response
from functools import update_wrapper
app = Flask(__name__)
# app.config.from_object('parkyou.default_settings')
# $ export PARKYOU_SETTINGS=conf/settings.cfg
app.config.from_envvar('PARKYOU_SETTINGS')
app.config["MONGODB_SETTINGS"] = {'DB': "parku"}
db = MongoEngine(app)
from parkyou.data import dbops
import json
# The center of the map will be Times Square
TS_LATITUDE = 40.759060
TS_LONGNITUDE = -73.984776
RADIUS = 1 # not sure what the unit on this is
def get_polylines():
polylines = []
regs = dbops.find_all_regulations((TS_LONGNITUDE , TS_LATITUDE), RADIUS)
for reg in regs:
signs = dbops.find_signs_for_regulation(reg.sg_order_n)
polylines.append(signs)
return polylines
def nocache(f):
def new_func(*args, **kwargs):
resp = make_response(f(*args, **kwargs))
resp.cache_control.no_cache = True
return resp
return update_wrapper(new_func, f)
@app.route('/')
@app.route('/index')
def index():
return "Happy Parking!"
@app.route('/map')
@app.route('/map/')
@nocache
def show_map():
regs = get_polylines()
zoom = 16
print "Found %d lines " % len(regs)
return render_template("nyc.html", API_KEY=app.config["GOOGLE_MAP_KEY"],
LAT=TS_LATITUDE,
LONG=TS_LONGNITUDE, ZOOM=zoom,
regulations=regs)
if __name__ == '__main__':
app.run()