-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (37 loc) · 1.05 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
42
43
44
45
46
47
48
49
50
51
from flask import Flask
from flask_api import FlaskAPI
from pandas_datapackage_reader import read_datapackage
from flask import (
url_for, redirect,
request, flash,
render_template,
send_from_directory,
)
try:
from .util import *
except:
from util import *
app = FlaskAPI(__name__)
# Create API endpoints
data = read_datapackage("data")
@app.route('/api/<resource>')
def api_dict(resource):
return get_paginated(request.args, data[resource])
@app.route('/api/<resource>.json')
def api_json(resource):
return get_paginated(request.args, data[resource], True)
@app.route('/api/<resource>/all.json')
def api_all_json(resource):
return data[resource].to_json(orient='records')
# Static views
@app.route('/')
def send_home():
return render_template('public/index.html')
@app.route('/static/<path:path>')
def send_static(path):
return send_from_directory('static', path)
@app.route('/images/<path:path>')
def send_images(path):
return send_from_directory('images', path)
if __name__ == '__main__':
app.run(debug=True)