forked from alykhank/NextRide
/
app.py
41 lines (33 loc) · 1.06 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
#!/usr/bin/env python
import os, requests, getSchedule
from flask import Flask, request, jsonify, render_template, abort
app = Flask(__name__)
@app.route('/')
def root():
return render_template('index.html')
@app.route('/m')
def mobileView():
stop = request.args.get('stop', 1, type=int)
schedule = getSchedule.parseSchedule(getSchedule.getRides(stop))
if schedule:
response = dict(meta=dict(status=200, message='OK'),data=schedule)
else:
abort(400)
return render_template('m.html', path=response)
@app.route('/api')
def api():
stop = request.args.get('stop', 1, type=int)
schedule = getSchedule.parseSchedule(getSchedule.getRides(stop))
if schedule:
response = jsonify(meta=dict(status=200, message='OK'),data=schedule)
else:
abort(400)
return response
@app.errorhandler(400)
def bad_request(error):
response = jsonify(meta=dict(status=error.code, message=error.message))
return response, error.code
if __name__ == "__main__":
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)