-
Notifications
You must be signed in to change notification settings - Fork 0
/
divvy.py
66 lines (53 loc) · 1.95 KB
/
divvy.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 os
import flask
from flask.ext import restless
from flask.ext.restless import APIManager
from database import db_session, init_db
from models import Station, Trip, TripLines, TripsByHour
#from cherrypy import wsgiserver
# Key vars
#WEB_DIR = 'web'
# Define static pages
#class Root(object):
# def index(self):
# return open(os.path.join(WEB_DIR, 'index.html'))
# index.exposed = True
#root = Root()
# restless docs
# https://flask-restless.readthedocs.org/en/latest/quickstart.html
# https://flask-restless.readthedocs.org/en/latest/searchformat.html
# Connect flask with SQLAlchemy
app = flask.Flask(__name__)
init_db()
manager = APIManager(app, session=db_session)
# Hook up with CherryPy
#d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
#restServer = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 9876), d)
# Create the API endpoints
station_blueprint = manager.create_api(Station,
methods=['GET'],
max_results_per_page=-1)
trip_blueprint = manager.create_api(Trip,
methods=['GET'],
max_results_per_page=100)
trip_lines_blueprint = manager.create_api(TripLines,
methods=['GET'],
max_results_per_page=-1)
trips_by_hour_blueprint = manager.create_api(TripsByHour,
methods=['GET'],
max_results_per_page=-1)
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
#if __name__ == '__main__':
# try:
# restServer.start()
# except KeyboardInterrupt:
# restServer.stop()
#app.run()
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
# test it at e.g.
# http://0.0.0.0:5000/api/station
# http://0.0.0.0:5000/static/index.html